C Programming Tutorial

Advertisements

Write C program to count total number of blank spaces in a file



       #include<stdio.h>
       #include<conio.h>
       #include<process.h>

       void main()
       {
              FILE *fp;
              char ch;
              int count=0;
              clrscr();

              fp = fopen("file.txt","r");
              
              if(fp == NULL)
              {
                     printf("\nCan't open file or file doesn't exist."); 
                     exit(0);
              }

              while((ch = fgetc(fp))!=EOF)
                  if(ch==' ')
                      count++;
                                      
               printf("\nTotal characters : %d",count);          
              fclose(fp);               

              getch();
       }




Advertisement