Re: Help. Where is my error?



"Red Dragon" <tskhoon@xxxxxxxxxxxx> writes:
> I am self study C student. I got stuck in the program below on quadratic
> equation and will be most grateful if someone could help me to unravel the
> mystery.
> Why does the computer refuse to execute my scanf ("%c",&q);

It doesn't. Your call to scanf("%c", &q) is doing exactly what it's
supposed to do.

To find out what it's supposed to do, read the documentation for
scanf().

You're almost certainly better off using a different method to read
input. A common technique is to use fgets() to read a line at a time,
then use sscanf() to parse the string. (This can have its own
drawbacks; fgets() either leaves the newline character in the input
string, or truncates the line if it's too long.)

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Re: Is C99 the final C? (some suggestions)
    ... fgets was designed to read text lines into a string. ... that fgetsdoes not ignore embedded null characters in text files. ... and puts it in the buffer nominated. ...
    (comp.lang.c)
  • Re: Reading Simple Flatfiles with a COBOL Mindset
    ... >all 5 data fields in one file read using fgets. ... the extracting data from the string that's been read in quite similar. ... at a time with fgets and then extract it. ... The internal representation in a struct can be easily made close to the ...
    (comp.lang.c)
  • Re: fgets question
    ... documentation didn't say if fgets put \0 after a string literal. ... fgets() has nothing at all to do with string literals. ... within the bounds of the array, then it is not a string. ... strlenon an array of characters that is not a string, ...
    (comp.lang.c)
  • Re: Segfault question.
    ... fgets returns a null pointer if it encounters either an EOF ... that strlenrequires a C string, and (char *)NULL does not qualify ...
    (comp.lang.c)
  • Re: reading from a text file
    ... Data with embedded nulls isn't text and should ... > returns a string consisting of every character up to the null. ... as opposed to modern fgets, which keeps on going and data beyond the ... meh - it was an int originally. ...
    (comp.lang.c)