Hey guys,
I have a code here i'm using for an exercise and basically it sorts a group of words of the user's choice and prints them in Dictionary order.
I have a few questions as I'm new to C programming and it's my first year of Computer Science.
First of all here's the code:
( sorry the code is like this.. don't know how to post it better )
Code:1 #include<stdio.h> 2 #include <string.h> 3 int main(){ 4 int i,j; 5 char str[10][50],temp[50]; 6 printf("Enter 10 words:\n"); 7 for(i=0;i<10;++i) 8 gets(str[i]); 9 for(i=0;i<9;++i) 10 for(j=i+1;j<10 ;++j){ 11 if(strcmp(str[i],str[j])>0) 12 { 13 strcpy(temp,str[i]); 14 strcpy(str[i],str[j]); 15 strcpy(str[j],temp); 16 } 17 } 18 printf("In lexicographical order: \n"); 19 for(i=0;i<10;++i){ 10 puts(str[i]); 21 } 22 return 0; 23 }
1st Question: Line-7 the for loop explains that user's printing 10 words no more (True/False)
2nd Question: Line-9 & 10 don't understand this loop. Can someone explain me?
3rd Question: Now i understand that the user needs to print 10 words after hitting "Enter" but how to change this code so that the user can insert a serie of words using spaces instead of pressing "Enter"?
I want it to scan only the first line that contains my group of words.
example: john jordan jake yann max kevin
instead of:
john
jordan
jake
yann
max
kevin