Hello there, I am having trouble copying text into a string, what am i doing wrong?

#include <stdio.h>

int main() {
	char instructions[80];
	
	FILE *f;
	f=fopen("a3.txt","r");
	
	while (fscanf(f,"%s",instructions != EOF){
		fscanf(f,"%s",instructions);
	}
	
	printf("%s",instructions);

	
	
}

the contents of a3.txt are
B404
239A
2412
5345
350C
C000.

Hello there, I am having trouble copying text into a string, what am i doing wrong?

#include <stdio.h>

int main() {
	char instructions[80];
	
	FILE *f;
	f=fopen("a3.txt","r");
	
	while (fscanf(f,"%s",instructions != EOF){
		fscanf(f,"%s",instructions);
	}
	
	printf("%s",instructions);

	
	
}

the contents of a3.txt are
B404
239A
2412
5345
350C
C000.

There are two things wrong with your code. In the 'while (fscanf(f,"%s",instructions != EOF)' line you have a missing "close paren". It should be 'while (fscanf(f,"%s",instructions) != EOF)'. The next problem is that you are reading your file twice. Once in the while statement and once in the body of the while statement. I would do the following

while (fscanf(f,"%s",instructions) != EOF){
printf("%s",instructions);
}

Comments
good explanation
This article has been dead for over six months. Start a new discussion instead.