Advertisement
HadoukenGr

Generate Word size

Jan 18th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. #define LOCALE_GR   "greek"
  2.  
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #include <locale.h>
  6. #include <string.h>
  7.  
  8. int main (void)
  9. {
  10.     FILE *fp;
  11.     FILE *fp1;
  12.     char words[30];
  13.     char *str;
  14.     int counter;
  15.  
  16.     char oldlocale[100+1]={0};
  17.     strncpy( oldlocale, setlocale(LC_ALL, NULL), 100 );
  18.  
  19.     char *cp = setlocale(LC_ALL, LOCALE_GR);
  20.     if ( !cp )
  21.         puts("could not change locale");
  22.     else
  23.         printf("Locale changed to: %s\n", cp);
  24.  
  25.     fp  = fopen("wordsgr.txt","r");
  26.     fp1 = fopen("wordssize.txt","w");
  27.  
  28. /* will open wordsgr.txt read each line and store the"how many chacters are per line" in a file called wordsize*/
  29.     while(1)
  30.     {
  31.         str = fgets(words,30,fp);
  32.  
  33.         if (str == NULL)
  34.         {
  35.             break;
  36.         }
  37.  
  38.          counter = 0;
  39.  
  40.          for (int i = 0; words[i] != '\n'; i++)
  41.         {
  42.             counter++;
  43.         }
  44.         printf("%s",words);
  45.         printf("%10.3d\n",counter);
  46.         fprintf(fp1,"%d\n",counter);
  47.  
  48.             if ( cp )
  49.         setlocale(LC_ALL, oldlocale);
  50.  
  51.  
  52.     }
  53. printf("\a");
  54.  
  55.     fclose(fp);
  56.     fclose(fp1);
  57.     return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement