this is my code and no matter what record number the user enters i cant get any of the records fields to read into the structure acct. What am i doing wrong?
#include <stdio.h>
typedef struct
{
char name[40];
int number;
float balance;
} acct_info_t;
int main (int argc, char *argv[])
{
FILE *ptr_acctfile;
acct_info_t acct;
ptr_acctfile = fopen("/accounts/facstaff/bhatias/cs2750/acct_info", "rb");
if (!ptr_acctfile)
{
printf("Unable to open file!\n");
return 1;
}
printf("Enter a record number: ");
int recnum;
scanf("%d", &recnum);
fseek(ptr_acctfile, sizeof(acct_info_t)*recnum, SEEK_SET);
fread(&acct, sizeof(acct_info_t), 1, ptr_acctfile);
printf("%s, %d\n", acct.name, acct.balance);
fclose(ptr_acctfile);
return 0;
}
ok also i guess im getting odd results since there are 2 integers i have to acount for in the beggining of the file. how would i get past these with an fseek?