Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- int main()
- {
- char ifname[100];
- char ofname[100];
- printf("input file>");
- scanf("%s",ifname);
- printf("output file>");
- scanf("%s",ofname);
- FILE* fin = fopen(ifname, "r");
- if( !fin ) return printf("\nError: can't open input file!\n\n");
- int f[1000], c=0,x=0,l=0,b=0;
- c=fgetc(fin);
- if(c!=' ' && c != '\n') b=1;
- do {
- c=fgetc(fin);
- if(c == ' ' || c == '\n' ) b = 1;
- if(b && (c == EOF || (c!=' ' && c != '\n'))) {x=x+1; b=0;}
- if(c == '\n' || c == EOF) {
- if( x < 8 )
- f[l] = 1;
- else
- f[l] = 0;
- printf("string #%d, words=%d, needs printing?=%d\n",l,x,f[l]);
- l=l+1;
- x = 0;
- }
- } while(c!=EOF);
- fclose(fin);
- fin = fopen(ifname, "r");
- FILE* fout = fopen(ofname, "w");
- if( !fout ) return printf("\nError: can't open output file!\n\n");
- l=0;
- while((c=fgetc(fin))!=EOF) {
- if( f[l] == 1 ) fputc(c,fout);
- if( c == '\n' ) l = l + 1;
- }
- fclose(fin);
- fclose(fout);
- printf("Done!");
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement