Hello. It is necessary to read the string and the character in the C language. I do it like this:

fscanf(mf, "%s%c", str, symb); 

Where mf is an open file. But the problem is that the character cannot be read, only the line is read. Here is the file to be read from:

 test s 

test is a string, s is a character. Tell me how to read them correctly?

    2 answers 2

    To begin with, %s read one word .
    Then %c , read the character. What is the character after the word test ? That is - the space.

    Next, where to read ? You must specify the address .

    So to read your test s you just need to write

     fscanf(mf, "%s %c", str, &symb); 

      You can do this as shown in the following demo.

       #include <stdio.h> int main( void ) { char s[10]; char c; fscanf( stdin, "%9[^ ^\t] %c", s, &c ); printf( "%s %c\n", s , c ); return 0; }