kev1_mc
July 3, 2005, 11:45 AM
somebody asked me wats wrong with this, but i'm a little rusty with c++ now. does anybody know wats wrong?
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define SIZE 2
typedef struct Account{
int accNum;
char name[10];
}Account;
void newRecord(FILE *);
int main(){
//int i=0;
FILE *cfPtr;
//Account Acc={0,""};
//cfPtr = fopen("Account1.txt", "a+");
if((cfPtr = fopen("Account1.txt", "a+"))==NULL)
printf("File could not be opened!");
newRecord(cfPtr);
/*else{
printf("Enter account number: ");
scanf("%d", &Acc.accNum);
while(Acc.accNum != 0){
printf("Enter account name: ");
fscanf(stdin,"%s", Acc.name);
fseek(fPtr,(Acc.accNum -1)*sizeof(Account), SEEK_SET);
fwrite(&Acc, sizeof(Account),1,fPtr);
printf("Enter account number: ");
scanf("%d", &Acc.accNum);
}//end while
}//end else
*/
fclose(cfPtr);
getch();
return 0;
}//end main
void newRecord(FILE *cfPtr){
Account Acc;
int accNum;
printf("Enter account number: ");
scanf("%d", &Acc.accNum);
fseek(cfPtr,(Acc.accNum-1)*sizeof(struct Account),SEEK_SET);
fread(&Acc, sizeof(Account),1,cfPtr);
printf("Enter account name: ");
scanf("%s", Acc.name);
//Acc.accNum = accNum;
fseek(cfPtr,(Acc.accNum-1)*sizeof(Account),SEEK_SET);
fwrite(&Acc, sizeof(Account),1,cfPtr);
}
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define SIZE 2
typedef struct Account{
int accNum;
char name[10];
}Account;
void newRecord(FILE *);
int main(){
//int i=0;
FILE *cfPtr;
//Account Acc={0,""};
//cfPtr = fopen("Account1.txt", "a+");
if((cfPtr = fopen("Account1.txt", "a+"))==NULL)
printf("File could not be opened!");
newRecord(cfPtr);
/*else{
printf("Enter account number: ");
scanf("%d", &Acc.accNum);
while(Acc.accNum != 0){
printf("Enter account name: ");
fscanf(stdin,"%s", Acc.name);
fseek(fPtr,(Acc.accNum -1)*sizeof(Account), SEEK_SET);
fwrite(&Acc, sizeof(Account),1,fPtr);
printf("Enter account number: ");
scanf("%d", &Acc.accNum);
}//end while
}//end else
*/
fclose(cfPtr);
getch();
return 0;
}//end main
void newRecord(FILE *cfPtr){
Account Acc;
int accNum;
printf("Enter account number: ");
scanf("%d", &Acc.accNum);
fseek(cfPtr,(Acc.accNum-1)*sizeof(struct Account),SEEK_SET);
fread(&Acc, sizeof(Account),1,cfPtr);
printf("Enter account name: ");
scanf("%s", Acc.name);
//Acc.accNum = accNum;
fseek(cfPtr,(Acc.accNum-1)*sizeof(Account),SEEK_SET);
fwrite(&Acc, sizeof(Account),1,cfPtr);
}