Thursday , September 21 2017
Home / C / C program to remove extra lines or blank lines from a file

C program to remove extra lines or blank lines from a file

C program for removing line spacing from a file and copying it to another file or program to remove extra blank lines within a file.

#include <stdio.h>
#include <stdlib.h>

int main()
{
    FILE *fp,*fp2;
    int p;
    char *filename;
            printf("enter the file name from which you have to remove the blank lines: ");
            scanf("%s",filename);
            printf("%s",filename);
            fp=fopen(filename,"r");
            fp2=fopen("newfile.txt","w");  //all the content gets copied to this filename and blank lines are also removed from your file

            while((p=getc(fp))!=EOF)
            {

                fputc(p,fp2);
                if (p==10)
                    {
                              while((p=getc(fp))==10)
                              {
                              }
                    fputc(p,fp2);
                    }
            }
fclose(fp);
fclose(fp2);
getch();
return 1;
}

OUTPUT:

blank lines removal

Tags: C program to remove blank lines from a file, c program to remove extra lines from a text file.

Check Also

How to Solve Linear Equation in One Variable In C Programming?

C Program to Solve any Linear Equation in One Variable Find complete C program to ...

Leave a Reply

Your email address will not be published. Required fields are marked *