Hi guys, i have to create a program that would store a persons full name, phone number, address, and postal code into a file named contactlist.dat, so far no problems, but im also supposed to use char for every single one, even the phone number, does anyone know how to do that? this is what i got so far for the code
#include <stdio.h>
struct contact {
char firstname [40];
char lastname [40];
char address [100];
char postalcode [6];
char phone[10];
};
int enterchoice (void);
int isvalidphone (void);
int isvalidpostal (void);
int isvalidaddress (void);
int main (void){
FILE *cfPtr;
int choice;
struct contact data = {"", "", "", "", ""};
if ((cfPtr = fopen ("contactlist.dat", "rb+")) == NULL){
printf ("File could not be opened.\n");
}
else{
while ((choice = enterchoice() != 6)) {
printf ("First name: ");
fscanf ("%s", data.firstname);
printf ("Last name: ");
fscanf ("%s", data.lastname);
printf ("Address: ");
fscanf ("%s", data.address);
printf ("Postal code: ");
fscanf ("%s", data.postalcode);
printf ("Phone number: ");
fscanf ("%s", data.phone);
fwrite (&data, sizeof (struct contact), 1, cfPtr);
printf ("Would you like to enter a new contact? (1/0)");
scanf ("%d", choice);
}
fclose (cfPtr);
}
return 0;
anyone know how to input a number as a character array???? or an alternative to that??
Any help is greatly appriciated!