Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define LOCALE_GR "greek"
- #include<stdio.h>
- #include<stdlib.h>
- #include <locale.h>
- #include <string.h>
- int main (void)
- {
- FILE *fp;
- FILE *fp1;
- char words[30];
- char *str;
- int counter;
- char oldlocale[100+1]={0};
- strncpy( oldlocale, setlocale(LC_ALL, NULL), 100 );
- char *cp = setlocale(LC_ALL, LOCALE_GR);
- if ( !cp )
- puts("could not change locale");
- else
- printf("Locale changed to: %s\n", cp);
- fp = fopen("wordsgr.txt","r");
- fp1 = fopen("wordssize.txt","w");
- /* will open wordsgr.txt read each line and store the"how many chacters are per line" in a file called wordsize*/
- while(1)
- {
- str = fgets(words,30,fp);
- if (str == NULL)
- {
- break;
- }
- counter = 0;
- for (int i = 0; words[i] != '\n'; i++)
- {
- counter++;
- }
- printf("%s",words);
- printf("%10.3d\n",counter);
- fprintf(fp1,"%d\n",counter);
- if ( cp )
- setlocale(LC_ALL, oldlocale);
- }
- printf("\a");
- fclose(fp);
- fclose(fp1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement