I work on the DOS platform only and I use the Turbo-c ver 3.0 compiler
I have written the following code:
# include <stdio.h>
# include <conio.h>
# include <string.h>
typedef struct
{
char custno[ 7]; /* customer no */
char accnum[14]; /* account no */
char acdesc[31]; /* account description */
char clrbal[16]; /* clear balance */
char acclim[14]; /* account limit */
char rofint[ 7]; /* rate of interest */
char group1[ 3]; /* group 1 for sub limits */
char group2[ 3]; /* group 2 for sub limits */
char group3[ 3]; /* group 3 for sub limits */
char acopen[ 2]; /* a/c open status 0 closed - 1 open */
} ACLIMITS;
ACLIMITS limit;
void getsub(char *sptr, char *dptr, int stpt, int n);
void main(void)
{
FILE *in;
char buffer[91], substr[50];
int size, counter=0;
long fpos;
size = sizeof(limit);
clrscr();
in = fopen("limit.dat","r+t" ; /* open the data file */
fpos=ftell(in);
fread(&limit, size, 1, in);
if (strcmp(limit.acopen,""!=0)
{
while (!feof(in))
{
strcpy(limit.acopen,"0"
fseek(in, fpos, SEEK_SET);
fwrite(&limit, size, 1, in);
fpos=ftell(in);
fread(&limit, size, 1, in);
}
}
rewind(in);
fclose(in);
The program is supposed to read each record. Amend a particular field (limit.acopen in this case) and write the record back into the same file. I am unable to get this thing going. Fread and fwrite move the record pointer, and i am therefore unable to over-write the record to the file at the same location. if i use ftell or fgetpos and fsetpos, the feof gets affected. How can i solve the problem? Please help.
Subra if you find this useful let me know at vksubra@icenet.net
I have written the following code:
# include <stdio.h>
# include <conio.h>
# include <string.h>
typedef struct
{
char custno[ 7]; /* customer no */
char accnum[14]; /* account no */
char acdesc[31]; /* account description */
char clrbal[16]; /* clear balance */
char acclim[14]; /* account limit */
char rofint[ 7]; /* rate of interest */
char group1[ 3]; /* group 1 for sub limits */
char group2[ 3]; /* group 2 for sub limits */
char group3[ 3]; /* group 3 for sub limits */
char acopen[ 2]; /* a/c open status 0 closed - 1 open */
} ACLIMITS;
ACLIMITS limit;
void getsub(char *sptr, char *dptr, int stpt, int n);
void main(void)
{
FILE *in;
char buffer[91], substr[50];
int size, counter=0;
long fpos;
size = sizeof(limit);
clrscr();
in = fopen("limit.dat","r+t" ; /* open the data file */
fpos=ftell(in);
fread(&limit, size, 1, in);
if (strcmp(limit.acopen,""!=0)
{
while (!feof(in))
{
strcpy(limit.acopen,"0"
fseek(in, fpos, SEEK_SET);
fwrite(&limit, size, 1, in);
fpos=ftell(in);
fread(&limit, size, 1, in);
}
}
rewind(in);
fclose(in);
The program is supposed to read each record. Amend a particular field (limit.acopen in this case) and write the record back into the same file. I am unable to get this thing going. Fread and fwrite move the record pointer, and i am therefore unable to over-write the record to the file at the same location. if i use ftell or fgetpos and fsetpos, the feof gets affected. How can i solve the problem? Please help.
Subra if you find this useful let me know at vksubra@icenet.net