This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

want to read string & blank with scanf

Hello to everyone,
i would like to read strings with scanf.

scanf("%s",&text);


My strings are normal spoken sentences. So there are blanks included in the string. Scanf terminates string- reading on 'blank'. Is there a workaround or should I write my own procedure with reading only characters

scanf("%c",&my_char)


then making decisions to put them in a string and terminate on CR LF. Sorry this is no especiall Keil thread, but would be nice to share some ideas :-)

Parents
  • would like to read strings with scanf.

    Then learn about it. Read your C textbook or the manual to find out which % format allows you to read arbitrary character sequences, rather than just up to the next whitespace character.

    Or consider that scanf() may not be the right tool for this job. There are more functions in <stdio.h>. Go figure.

Reply
  • would like to read strings with scanf.

    Then learn about it. Read your C textbook or the manual to find out which % format allows you to read arbitrary character sequences, rather than just up to the next whitespace character.

    Or consider that scanf() may not be the right tool for this job. There are more functions in <stdio.h>. Go figure.

Children