Advertisement
Guest User

1_5

a guest
Apr 8th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define W 5
  4.  
  5. void addWord(char array[W][10], int i);
  6. void copyArray(char init[W][10], char final[W][10]);
  7. void capitalize(char array[W][10]);
  8.  
  9. int main() {
  10.     char words[W][9 + 1], newWords[W][10];
  11.     char test[9 + 1];
  12.     char endword[9 + 1] = "end";
  13.     int i = 0, j = 0;
  14.     printf("Submit up to 5 words, press 'end' to ...end.\n");
  15.     while (i<W)
  16.     {
  17.         scanf("%s", test);
  18.         if(strcmp(test,endword))
  19.         {
  20.             if (strlen(test) > 9)
  21.             {
  22.                 continue;
  23.             }
  24.             else
  25.             {
  26.                 strcpy(words[i++], test);
  27.                 printf("%s\n", test);
  28.             }
  29.         }
  30.         else
  31.         {
  32.             break;
  33.         }
  34.     }
  35.     putchar('\n');
  36.     printf("The strings:\n");
  37.     for (j=0; j<i; j++)
  38.     {
  39.         printf("%d\t%s\n", j, words[j]);
  40.     }
  41.     putchar('\n');
  42.     copyArray(words, newWords);
  43.     putchar('\n');
  44.     for (j=0; j<i; j++)
  45.     {
  46.         printf("%d\t%s\n", j, newWords[j]);
  47.     }
  48.     putchar('\n');
  49.     capitalize(newWords);
  50.     putchar('\n');
  51.     for (j=0; j<i; j++)
  52.     {
  53.         printf("%d\t%s\n", j, newWords[j]);
  54.     }
  55.     putchar('\n');
  56.     addWord(newWords, i);
  57.     putchar('\n');
  58.     if (i==W)
  59.     {
  60.         for (j=0; j<i; j++)
  61.         {
  62.             printf("%d\t%s\n", j, newWords[j]);
  63.         }
  64.     }
  65.     else
  66.     {
  67.         for (j=0; j<i+1; j++)
  68.         {
  69.             printf("%d\t%s\n", j, newWords[j]);
  70.         }
  71.        
  72.     }
  73.     return 0;
  74. }
  75.  
  76. void copyArray(char init[W][10], char final[W][10])
  77. {
  78.     int i;
  79.     for (i=0;i<W;i++)
  80.     {
  81.         strcpy(final[i], init[i]);
  82.     }
  83.     printf("Array successfully duplicated.");
  84.     return;
  85. }
  86.  
  87. void capitalize(char array[W][10])
  88. {
  89.     int i;
  90.     for (i=0;i<W;i++)
  91.     {
  92.         strcpy(array[i],strupr(array[i]));
  93.     }
  94.     printf("Array successfully capitilized.");
  95.     return;
  96. }
  97.  
  98. void addWord(char array[W][10], int i)
  99. {
  100.     char newWord[10];
  101.     int j, nono;
  102.     nono=10;
  103.     printf("Please type the word!\n");
  104.     scanf("%s", newWord);
  105.     while (nono>=i)
  106.     {
  107.         printf("Where do you want to put it in (possible numbers 0 - %d)?\n", i-1);
  108.         scanf("%d", &nono);
  109.     }
  110.     for (j=i;j>=0;j--)
  111.     {
  112.         if (j+1 == nono)
  113.         {
  114.             break;
  115.         }
  116.         memmove(array[j+1], array[j], 10); 
  117.     }
  118.     memmove(array[nono], newWord, 10);
  119.     return;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement