[LIP] C file read
alok bharti <alok_mact-/[email protected]>
| Newsgroups | gmane.user-groups.linux.india.programmers |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I have function which is callled to read from a file.
it opens the file, once the data is read closes the
file and returns.
after some time the same function is called.
and in between the file content is manually changed.
still the function read the old data. may be somewhere
from some old buffer. I expect my function to read the
new data in the file.
here is the code snippet.
...
...
read_file()
{
FILE *in;
char *confpath;
char *filename = "test2.xml";
char filepath[256];
int rc=0;
/*
*
* * check for ENV variable XMLFILEPATH
*/
confpath = getenv("XMLFILEPATH");
if (NULL == confpath) {
fprintf(stderr, "%s:XMLFILEPATH not set",
__FUNCTION__);
return (-1);
}
sprintf(filepath, "%s/%s", confpath, filename);
if (!(in = fopen(filepath, "r"))) {
printf("Unable to open input file %s\n",
filepath);
return (-1);
}
printf("%s: file opened \n", __FUNCTION__);
for (;;) {
int done = 0;
int len = 0;
len = fread(Buff, 1, sizeof(Buff), in);
done = len < sizeof(Buff);
//....
//some code to deal with the data just read
//....
if (done)
break;
}
printf("%s: file closed \n", __FUNCTION__);
rc = fclose(in);
if(0!=rc)
printf("%s \n", strerror(errno));
return 0;
}
...
...
Please help and suggest where is the mistake.
For the first call this function works fine.
when recalled after sometime when the file content are
changed, it still reads the old data. strange that the
data in the file is now changed.
Regards,
Alok
____________________________________________________________________________________Pinpoint customers who are looking for what you sell.
http://searchmarketing.yahoo.com/
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/