I've done a search and came up with nothing helpful....
I have been stuck at this for a few day's now , I need too write a program that will use scanf() to read in seven strings input by the user. The program should print the seven strings as a list , then sort them alphabettically and print a new list.
I need to use the function strcmp() , & the preprocessing directive #define N_STRINGS 7 to assist in the sorting of the strings
I have tried using for loops & while loops with scanf() in reading in the strings , & then printing it out but im all ready stuck
At this point im just trying to get my code to read 7 strings input by the user & just print them out again.
This is what i've come up with sofar but it's not working at all & very long .
Code:#include <stdio.h> #include <string.h> #define N_STRINGS 7 #define SIZE 100 #define SIZED 700 void main(int argc) { char c; int i; int count = 0; char array1[SIZE]; char array2[SIZE]; char array3[SIZE]; char array4[SIZE]; char array5[SIZE]; char array6[SIZE]; char array7[SIZE]; printf("Type in 7 strings...\n\n"); if (argc < SIZED){ while ((c = getchar()) != '\n'){ scanf("%s", array1); count++; } array1[count - 1] = '\0'; count = 0; while ((c = getchar()) != '\n'){ scanf("%s", array2); count++; } array2[count - 1] = '\0'; count = 0; while ((c = getchar()) != '\n'){ scanf("%s", array3); count++; } array3[count - 1] = '\0'; count = 0; while ((c = getchar()) != '\n'){ scanf("%s", array4); count++; } array4[count - 1] = '\0'; count = 0; while ((c = getchar()) != '\n'){ scanf("%s", array5); count++; } array5[count - 1] = '\0'; count = 0; while ((c = getchar()) != '\n'){ scanf("%s", array6); count++; } array6[count - 1] = '\0'; count = 0; while ((c = getchar()) != '\n'){ scanf("%s", array7); count++; } array7[count - 1] = '\0'; } else { printf("Type in 7 strings...\n"); } printf("\n"); printf("Printing the strings again ...\n"); for (i = 0;(c = getchar()) != '\0';++i){ printf("%s",array1[i]); } for (i = 0;(c = getchar()) != '\0';++i){ printf("%s",array2[i]); } for (i = 0;(c = getchar()) != '\0';++i){ printf("%s",array3[i]); } for (i = 0;(c = getchar()) != '\0';++i){ printf("%s",array4[i]); } for (i = 0;(c = getchar()) != '\0';++i){ printf("%s",array5[i]); } for (i = 0;(c = getchar()) != '\0';++i){ printf("%s",array6[i]); } for (i = 0;(c = getchar()) != '\0';++i){ printf("%s",array7[i]); } }
Thanks a lot for any help![]()
Btw I must use scanf() in reading in the strings it says so in my textbook .



LinkBack URL
About LinkBacks





