Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define W 5
- void addWord(char array[W][10], int i);
- void copyArray(char init[W][10], char final[W][10]);
- void capitalize(char array[W][10]);
- int main() {
- char words[W][9 + 1], newWords[W][10];
- char test[9 + 1];
- char endword[9 + 1] = "end";
- int i = 0, j = 0;
- printf("Submit up to 5 words, press 'end' to ...end.\n");
- while (i<W)
- {
- scanf("%s", test);
- if(strcmp(test,endword))
- {
- if (strlen(test) > 9)
- {
- continue;
- }
- else
- {
- strcpy(words[i++], test);
- printf("%s\n", test);
- }
- }
- else
- {
- break;
- }
- }
- putchar('\n');
- printf("The strings:\n");
- for (j=0; j<i; j++)
- {
- printf("%d\t%s\n", j, words[j]);
- }
- putchar('\n');
- copyArray(words, newWords);
- putchar('\n');
- for (j=0; j<i; j++)
- {
- printf("%d\t%s\n", j, newWords[j]);
- }
- putchar('\n');
- capitalize(newWords);
- putchar('\n');
- for (j=0; j<i; j++)
- {
- printf("%d\t%s\n", j, newWords[j]);
- }
- putchar('\n');
- addWord(newWords, i);
- putchar('\n');
- if (i==W)
- {
- for (j=0; j<i; j++)
- {
- printf("%d\t%s\n", j, newWords[j]);
- }
- }
- else
- {
- for (j=0; j<i+1; j++)
- {
- printf("%d\t%s\n", j, newWords[j]);
- }
- }
- return 0;
- }
- void copyArray(char init[W][10], char final[W][10])
- {
- int i;
- for (i=0;i<W;i++)
- {
- strcpy(final[i], init[i]);
- }
- printf("Array successfully duplicated.");
- return;
- }
- void capitalize(char array[W][10])
- {
- int i;
- for (i=0;i<W;i++)
- {
- strcpy(array[i],strupr(array[i]));
- }
- printf("Array successfully capitilized.");
- return;
- }
- void addWord(char array[W][10], int i)
- {
- char newWord[10];
- int j, nono;
- nono=10;
- printf("Please type the word!\n");
- scanf("%s", newWord);
- while (nono>=i)
- {
- printf("Where do you want to put it in (possible numbers 0 - %d)?\n", i-1);
- scanf("%d", &nono);
- }
- for (j=i;j>=0;j--)
- {
- if (j+1 == nono)
- {
- break;
- }
- memmove(array[j+1], array[j], 10);
- }
- memmove(array[nono], newWord, 10);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement