Advertisement
Nahid8195

File Management in C

Dec 8th, 2022
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. int main()
  4. {
  5.     FILE *fp, *fp2, *fp3;
  6.     int vowel = 0, consonant = 0;
  7.     char ch;
  8.     char message[200];
  9.  
  10.     fp = fopen("E:\\Lab 2\\input.txt", "r");
  11.     fp2 = fopen("E:\\Lab 2\\vowel.txt", "w");
  12.     fp3 = fopen("E:\\Lab 2\\consonant.txt", "w");
  13.  
  14.     if (!fp)
  15.     {
  16.         perror("Error: ");
  17.         exit(1);
  18.     }
  19.  
  20.     while (!feof(fp))
  21.     {
  22.         fgets(message, 200, fp);
  23.         printf("%s", message);
  24.     }
  25.     printf("\n\n");
  26.  
  27.     fseek(fp, 0, SEEK_SET);
  28.  
  29.     while (ch != EOF)
  30.     {
  31.         ch = fgetc(fp);
  32.         if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
  33.         {
  34.             if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
  35.             {
  36.                 fputc(ch, fp2);
  37.                 vowel++;
  38.             }
  39.             else
  40.             {
  41.                 fputc(ch, fp3);
  42.                 consonant++;
  43.             }
  44.         }
  45.     }
  46.  
  47.     fprintf(fp2, "\nCount:%d", vowel);
  48.     fprintf(fp3, "\nCount:%d", consonant);
  49.  
  50.     fclose(fp);
  51.     fclose(fp2);
  52.     fclose(fp3);
  53.     return 0;
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement