Hey folks,
Working on a project here and I can't figure out why my loop won't iterate within my function. It's the for loop at the end. Could you take a look?
Code:
//Load File
void load(entry *phonebook, int numOfEntries) {
FILE *pRead;
double totalSize;
int num, m = 0;
//Begin Reading
pRead = fopen("phoneBook.txt", "r");
if(pRead == NULL) {
printf("\nFile Can't be Opened\n");
}// End if
//Else Read Sucessfull
else {
//Find File Total Size
fscanf(pRead, "%d", &totalSize);
printf("\nGot total size. Total size is %d\n", totalSize);
//reallocate memory
entry *temp = realloc(phonebook, (totalSize+1) * sizeof(entry));
//Debugging memory allocation error
if (temp == NULL){
printf("\nMemory Allocation Error in LOAD FILE\n");
}//End Debugging If
//Memory allocation successfull
else {
phonebook = temp;
printf("\nMemory Allocation Sucessful\n");
}//End Else
for(m=0; m < totalSize; m++){
printf("1st time: i is %i, totalSize is %d\n", m, totalSize);phonebook[i].fName);
printf("2nd time: i is now %i, totalSize is %d\n", m, totalSize);
}
printf("out of loop: i is now %i, totalSize is %d\n", m, totalSize);
} //End Read Sucessful Else
fclose(pRead);
}// End Load File