Advertisement
Guest User

Untitled

a guest
May 25th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. int main()
  5. {
  6.   char ifname[100];
  7.   char ofname[100];
  8.   printf("input file>");
  9.   scanf("%s",ifname);
  10.   printf("output file>");
  11.   scanf("%s",ofname);
  12.  
  13.   FILE* fin = fopen(ifname, "r");
  14.   if( !fin ) return printf("\nError: can't open input file!\n\n");
  15.  
  16.   int f[1000], c=0,x=0,l=0,b=0;
  17.  
  18.   c=fgetc(fin);
  19.   if(c!=' ' && c != '\n') b=1;
  20.   do {
  21.     c=fgetc(fin);
  22.     if(c == ' ' || c == '\n' ) b = 1;
  23.     if(b && (c == EOF || (c!=' ' && c != '\n'))) {x=x+1; b=0;}
  24.     if(c == '\n' || c == EOF) {
  25.       if( x < 8 )
  26.         f[l] = 1;
  27.       else
  28.         f[l] = 0;
  29.       printf("string #%d, words=%d, needs printing?=%d\n",l,x,f[l]);
  30.       l=l+1;
  31.       x = 0;
  32.     }
  33.   } while(c!=EOF);
  34.  
  35.   fclose(fin);
  36.  
  37.   fin = fopen(ifname, "r");
  38.   FILE* fout = fopen(ofname, "w");
  39.  
  40.   if( !fout ) return printf("\nError: can't open output file!\n\n");
  41.  
  42.   l=0;
  43.   while((c=fgetc(fin))!=EOF) {
  44.     if( f[l] == 1 ) fputc(c,fout);
  45.     if( c == '\n' ) l = l + 1;
  46.   }
  47.  
  48.   fclose(fin);
  49.   fclose(fout);
  50.  
  51.   printf("Done!");
  52.   getch();
  53.  
  54.   return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement