SHARE
TWEET

Untitled

a guest Sep 17th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. int cnt=0;
  5. char change(char words[])
  6. {
  7.     strlwr(words);
  8. }
  9. int main(void)
  10. {
  11.     FILE* input=fopen("input.txt","r");
  12.     FILE* output=fopen("output.txt","w");
  13.    
  14.     if( input == NULL || output == NULL)
  15.     {
  16.         printf("開檔失敗!");
  17.         return -1;
  18.     }
  19.    
  20.     int i;
  21.     char words[300][20];
  22.     while(fscanf(input, "%s",words[cnt])!=EOF)
  23.         {
  24.             change(words[cnt]);
  25.             //strlwr(words);
  26.             cnt++;
  27.         }
  28.         /*
  29.     for(i=0;i<cnt;i++)
  30.     {
  31.         printf("%s %d\n",words[i],i);
  32.        
  33.     }*/
  34.    
  35.     //printf("\n\n\n\n\n");
  36.     int k,j;
  37.     char temp[20];
  38.    
  39. for(k=20;k>=0;k--){
  40.     for(i=0;i<cnt;i++)
  41.     {
  42.         for(j=0;j<cnt-1;j++)
  43.         {
  44.             //printf("%d",strcmp(words[j],words[j+1]));
  45.             if(strcmp(words[j],words[j+1]) == 1);
  46.             {
  47.                 strcpy(temp,words[j+1]);
  48.                 //printf("%s\n",temp);
  49.                 strcpy(words[j+1],words[j]);
  50.                 strcpy(words[j],temp);
  51.                 //printf("%d\n",j);
  52.             }
  53.         }
  54.     }
  55.     }
  56.     for(i=0;i<cnt;i++)
  57.     {
  58.         printf("%s\n",words[i]);
  59.     }
  60.    
  61.    
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top