/*
* DeleteTrace.c
*
* Created on: Feb 1, 2011
* Author: Karthikeyan.D
*/
# include <stdio.h>
# include <conio.h>
# include <windows.h>
# include <stdlib.h>
int main()
{
// Variable Declaration
FILE *FRead,*FWrite;
char SzContent[1000];
long int nloop;
long int nLineIndex;
/* File read and Read/write Mode Operation*/
// Here You Can Your File Location.
printf("Enter file File Path \n");
gets(SzContent);
FRead = fopen(SzContent,"r");
FWrite = fopen(SzContent,"r+");
if(FRead == NULL)
{
MessageBox(NULL,"Please Specify Already Created File Location ","Error in File Location",16);
exit(0);
}
printf("Enter the Line Index \n");
scanf("%ld",&nLineIndex);
/* This function is used to remove the number lines*/
for (nloop=0;nloop<nLineIndex;nloop++)
{
fgets(SzContent,1000,FRead);
}
/* This function is used to overwrite content from the top of the line*/
while(fgets(SzContent,1000,FRead)!=NULL)
{
fprintf(FWrite,SzContent);
}
/* To close the Two File Pointer */
fclose(FRead);
fclose(FWrite);
getch();
return 0;
}
Using this program , we can overwrite a same file without creating a new file. This code is very useful in the case of memory constrain.
ReplyDeleteFor Example, I have iGB Memory in my system, I want to open a 1GB or more than that size .txt file in my system.
In most of the case , we are facing system hanging problem. To avoid this problem, and to view the particular number of line in that huge document; it is very useful this kind of application.