First post here. I built a function that should get a string and an integer from two separate files, and save them to two variables. My code is:
void getCompanyData(char * companyData, int * checkNum){
char buffer[100];
FILE * tempFile1;
FILE * tempFile2;
tempFile1 = fopen("./companyData.txt", "r");
if (tempFile1 == NULL) {
printf("The file failed to open!\n");
exit(1);
}
while ((fgets(buffer, sizeof(buffer), tempFile1) != NULL)){
strcat(companyData, buffer);
}
fclose(tempFile1);
tempFile2 = fopen("./checkNum.txt", "r");
if (tempFile2 == NULL){
printf("The file failed to open!\n");
exit(1);
}
while (tempFile2 != NULL){
fscanf(tempFile2, "%d", checkNum);
}
fclose(tempFile2);
}
From the companyData.txt file:
Sabre Corporation
15790 West Henness Lane
New Corio, New Mexico 65790
From checkNum.txt: 100
source
share