Good day! I ask you to tell me about the entry of data in the file, and most importantly - reading from the file. I know the fscanf function, but for some reason, its calling does not give me what I need. I want to clarify, fprintf - puts data into a file, and fscanf - copies from file to a variable? Here is my program:
FILE *fp; fp=fopen("ro.txt", "w"); printf("vozrast? \n"); scanf ("%d", &K); fprintf(fp, "%d", K); fp=fopen("ro.txt", "r"); while (!feof(fp)) { fscanf(fp, "%d", &new_K); } printf("%d", new_K); As I understand it, the number should be recorded from the notepad in new_k , however, for some reason, a foreign value is recorded and displayed on the screen. Tell me, plz, what am I wrong?