Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- int cnt=0;
- char change(char words[])
- {
- strlwr(words);
- }
- int main(void)
- {
- FILE* input=fopen("input.txt","r");
- FILE* output=fopen("output.txt","w");
- if( input == NULL || output == NULL)
- {
- printf("開檔失敗!");
- return -1;
- }
- int i;
- char words[300][20];
- while(fscanf(input, "%s",words[cnt])!=EOF)
- {
- change(words[cnt]);
- //strlwr(words);
- cnt++;
- }
- /*
- for(i=0;i<cnt;i++)
- {
- printf("%s %d\n",words[i],i);
- }*/
- //printf("\n\n\n\n\n");
- int k,j;
- char temp[20];
- for(k=20;k>=0;k--){
- for(i=0;i<cnt;i++)
- {
- for(j=0;j<cnt-1;j++)
- {
- //printf("%d",strcmp(words[j],words[j+1]));
- if(strcmp(words[j],words[j+1]) == 1);
- {
- strcpy(temp,words[j+1]);
- //printf("%s\n",temp);
- strcpy(words[j+1],words[j]);
- strcpy(words[j],temp);
- //printf("%d\n",j);
- }
- }
- }
- }
- for(i=0;i<cnt;i++)
- {
- printf("%s\n",words[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement