When I run my program I get this...
where am I going wrong?
"lab7.c", line 4: warning: invalid white space character in directive
"lab7.c", line 38: warning: implicit function declaration: strcpy
"lab7.c", line 82: warning: newline not last character in file
luna:~>a.out
Segmentation fault (core dumped)
Code:// the purpose of this lab is to read data from a file, capitalize the first letter of all the names // in the file and rewrite the file // includes #include <stdio.h> struct employee { char firstname[40]; char lastname[40]; int id; }; typedef struct employee Employee; Employee e[3]; void PrintEmployeeRecord(); void SaveEmployeeRecord(); //void Capitalize(const Employee e[]); int main () { Employee e[3]; FILE *file; file = fopen("employee.dat", "r");// open file int i = 0; int c = 0; int tID = 0; char tFName[20]; char tLName[20]; do { c = fscanf(file,"%d %s %s" , &tID,tFName,tLName); if (c == 3) // all three matched the format { e[i].id = tID; strcpy(e[i].firstname, tFName); strcpy(e[i].lastname,tLName); i++ ; } } while ( c > EOF ); // end of file fclose(file); //close file PrintEmployeeRecord(); //Capitalize(e); PrintEmployeeRecord(); SaveEmployeeRecord(e); } // end of main // the function saves the employee data to a file // the input is an array of 3 and the output is a file with the employee data void SaveEmployeeRecord(const Employee e[]) { int i; FILE *file; file = fopen("employee.dat", "w"); // open the file fprintf(file, "ID FIRSTNAME LASTNAME\n"); // header for (i=0; i<3; i++) { fprintf(file, "%d %s %s\n", e[i].id, e[i].firstname, e[i].lastname); // print the data } fclose(file); // close the file } //purpose: Print Employee data //input: array of 3 employee data //output: 3 employee data printed to screen void PrintEmployeeRecord() { int i; for (i=0; i<3; i++); { printf("%d %s %s \n", e[i].id, e[i].firstname, e[i].lastname); } }



LinkBack URL
About LinkBacks



