#include <stdio.h> #include <stdlib.h> #include <locale.h> #include <malloc.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; } } printf("\nsort:\n"); for (n = 0; n < size; n++) printf("%s ",words[n] ); } int main() { char *words[5]; char word[5][50]; int i; for (i=0;i<5;i++){ printf("slovo:"); gets(word[i]); words[i]=word[i]; } int size =sizeof(words)/sizeof(char*); sort(words,size); } How can I enter a string using strtok, and not word for word as above? (Sort alphabetically, but I would like the string to be entered right away)
scanf("%s")? - pavel