i have my recipes.txt files filledCode:#include <stdio.h> #include <stdlib.h> // struct containing recipe typedef struct { char recipeName[40]; char recipeHowTo[1000]; int howManyPerson; int level; int timeToEat; } recipe; // struct for list struct element { recipe data; struct element *elemPtr; }; // prototypes struct element *menu(int choice, struct element *list); struct element *insertRecipe(struct element *listPtr); struct element *editRecipe(struct element *listPtr); void listRecipes(struct element *listPtr); void saveRecipes(struct element *listPtr); struct element *loadRecipes(struct element *listPtr); int main() { int choice = 2 ; struct element *list = NULL; int status = 0; while( status != 1 ){ list = loadRecipes(list); } system("PAUSE"); return 0; } //LOAD RECIPES struct element *loadRecipes(struct element *listPtr){ FILE *filePtr = fopen("recipes.txt","r"); recipe x; struct element *xPtr; if(( filePtr = fopen("recipes.txt","rb"))== NULL){ printf("Error in file opening"); } printf("debug1"); while( fread(&x,sizeof(recipe),1,filePtr) != NULL ){ printf("debug2"); if(listPtr == NULL){ printf("debug3"); listPtr = (struct element *) malloc(sizeof (struct element)); strcpy(listPtr->data.recipeName,x.recipeName); strcpy(listPtr->data.recipeHowTo,x.recipeHowTo); //strcpy(listPtr->data.howManyPerson,x.howManyPerson); //strcpy(listPtr->data.level,x.level); //strcpy(listPtr->data.timeToEat,x.t); listPtr->elemPtr = NULL; }else{ printf("debug4"); xPtr = (struct element *) malloc(sizeof (struct element)); strcpy(xPtr->data.recipeName,x.recipeName); strcpy(xPtr->data.recipeHowTo,x.recipeHowTo); //strcpy(xPtr->data.howManyPerson,x.howManyPerson); //strcpy(xPtr->data.level,x.level); //strcpy(xPtr->data.timeToEat,x.t); xPtr->elemPtr = xPtr; listPtr = xPtr; } }fclose(filePtr); return(listPtr); } //SAVE TO TXT void saveRecipes(struct element *listPtr){ FILE *stream = fopen("recipes.txt","w"); while(listPtr != NULL) { fprintf(stream,"%s\n%s\n%d%d%d\n\n",listPtr->data.recipeName,listPtr->data.recipeHowTo,listPtr->data.howManyPerson,listPtr->data.level,listPtr->data.timeToEat); listPtr = listPtr->elemPtr; } fflush(stream); fclose(stream); }
but when i run this program it arrive to debug1
and can't enter in the while that read the data and load them to the list