#include #define FNAME_SIZE 40 + 1 #define LNAME_SIZE 40 + 1 #define ADDRESS_SIZE 80 + 1 #define PHONE_SIZE 10 void storeData(char [], char [], char [], char[]); void clearInput(); int main(void) { char firstName[FNAME_SIZE], lastName[LNAME_SIZE]; char streetAddress[ADDRESS_SIZE]; char phoneNumber[PHONE_SIZE]; storeData(lastName, firstName, streetAddress, phoneNumber); return 0; } /* End of main program */ void storeData(char firstName[], char lastName[], char streetAddress[], char phoneNumber[]) { FILE *fp; char goAgain = 'Y'; fp = fopen("phone.txt", "w"); while (toupper (goAgain) == 'Y') { printf ("Please enter last name: "); scanf ("%40[^\n]", lastName); clearInput(); printf ("Please enter first name: "); scanf ("%40[^\n]", firstName); clearInput(); printf ("Please enter the street address: "); scanf ("%80[^\n]", streetAddress); clearInput(); printf ("Please enter phone number: "); scanf ("%10[^\n]", phoneNumber); clearInput(); fprintf (fp, "%s;%s;%s;%s\n", lastName, firstName, streetAddress, phoneNumber); printf ("Go Again? (Y/N): "); scanf (" %c", &goAgain); clearInput(); } /* End of while loop to continually write to file until "n" or "N" at Go Again? prompt */ fclose(fp); } /* End of storeData() function */ void clearInput(void) { while(getchar() != '\n') ; } /* End of clearInput() function */