do all files end in null?
Posted: Thu Apr 16, 2009 1:56 pm
Hi guys,
When I run my function below, I get stuck in an infinite loop.
From and to are filenames for txt files that already exist.
The only thing I can think of is that the txt file does not end in a
NULL pointer. Am I missing something?
//---------------------------------------------------------------------------
//Copy all lines except the first one
//into another file.
// from and to are char arrays of filenames
//---------------------------------------------------------------------------
void copyNotFirstLn (char *from, char *to)
{
F_FILE *fp1;
F_FILE *fp2;
char readbuf[100];
int i=0;
fp1=f_open(from, "r"); // open for reading
fp2=f_open(to, "w+"); // open for writing, delete anything already in file, create file if necessary
f_fgets(readbuf,100,fp1); // read through first line
// read fp1 one line at a time (up to 100 chars), and write to fp2
while (f_fgets( readbuf, 100 , fp1 )!= NULL)
{
iprintf("%d",i);
f_write( readbuf, 1, strlen( readbuf ), fp2 );
i++;
}
f_close(fp1);
f_close(fp2);
}
When I run my function below, I get stuck in an infinite loop.
From and to are filenames for txt files that already exist.
The only thing I can think of is that the txt file does not end in a
NULL pointer. Am I missing something?
//---------------------------------------------------------------------------
//Copy all lines except the first one
//into another file.
// from and to are char arrays of filenames
//---------------------------------------------------------------------------
void copyNotFirstLn (char *from, char *to)
{
F_FILE *fp1;
F_FILE *fp2;
char readbuf[100];
int i=0;
fp1=f_open(from, "r"); // open for reading
fp2=f_open(to, "w+"); // open for writing, delete anything already in file, create file if necessary
f_fgets(readbuf,100,fp1); // read through first line
// read fp1 one line at a time (up to 100 chars), and write to fp2
while (f_fgets( readbuf, 100 , fp1 )!= NULL)
{
iprintf("%d",i);
f_write( readbuf, 1, strlen( readbuf ), fp2 );
i++;
}
f_close(fp1);
f_close(fp2);
}