Using scanf and fgets in the same program?

The first problem is that the scanf() reads two characters, but not the newline afterwards. That means your fgets() reads the newline and finishes. You are lucky your program is not crashing. You tell fgets() that it is getting an array of 35 characters, but rather than passing an array, you pass the character (not … Read more

How to skip a line when fscanning a text file?

I was able to skip lines with scanf with the following instruction: fscanf(config_file, “%*[^\n]\n”); The format string matches a line containing any character including spaces. The * in the format string means we are not interested in saving the line, but just in incrementing the file position. Format string explanation: % is the character which … Read more

Dynamic String Input – using scanf(“%as”)

The a modifier to scanf won’t work if you are compiling with the -std=c99 flag; make sure you aren’t using that. If you have at least version 2.7 of glibc, you can and should use the m modifier in place of a. Also, it is your responsibility to free the buffer.

If statements not working?

You’re confusing the assignment operator = with the equals operator ==. Write this instead: if (battlechoice == 4) And so on. Some C programmers use “Yoda conditionals” to avoid accidentally using assignment in these cases: if (4 == battlechoice) For example this won’t compile, catching the mistake: if (4 = battlechoice)