Help, wrote a program to sort the string alphabetically. How can you alter the string to be entered, the head no longer cooks.

#include <stdio.h> #include <stdlib.h> void sort(char **words,int size) { int n,m,code; char *temp; for(n=1; n<size; n++) for(m=0; m<size-n; m++) { code=strcmp(words[m],words[m+1]); if(code>0) { temp=words[m]; words[m]=words[m+1]; words[m+1]=temp; } } for (n = 0; n < size; n++) printf("%s ",words[n] ); } int main() { char *words []= {"fake","bus","atom"}; int size =sizeof(words)/sizeof(char*); sort(words,size); } 

    1 answer 1

    Napimer so

     char str[80]; /* в переменную str считывается не более 79 символов */ scanf("%79s", str); 
    • it won't work out like this - Zhenya
    • @ Artem well, not str, so words - iFr0z