Hi, I need some help from u again..... if we type:
Enter Input : eee ddd cccc
the result should be like this :
sorting : ddd eee cccc
but actual result is like this :
sorting : eee eee cccc
I don't know why... Can u help me ?? Here is my code....
void wordSorter()
{
char input[60], word[10][30], *temp;
int i, count= 0, j = 0, sort1, sort2;
printf("\n4) Word Sorter\n");
printf("--------------\n");
printf("Enter string(s) (1 - 60 characters): ");
fgets(input, 61, stdin);
if(strlen(input) >= 60) readRestOfLine();
i = strlen(input)-1;
if( input[ i ] == '\n') input[i] = '\0';
for( i = 0; i <= strlen(input) && input[i] != '\0' && input[i] != '\n'; i++)
{
if(input[i] == ' ') {word[count][j] = '\0';count++;j = 0;}
else {word[count][j] = input[i];j++;}
word[count][j] = '\0';
}
for(sort1 = 0; sort1 <= count; ++sort1)
for(sort2 = sort1 + 1; sort2 <= count; ++sort2)
if(strcmp(word[sort1], word[sort2]) > 0)
{
temp = word[sort1];
strcpy(word[sort1],word[sort2]);
strcpy(word[sort2],temp);
};
printf("\nList of unique words: ");
for(i = 0; i<= count; i++)
printf("%s ",word[i]);
...
}