String reading issue using scanf?

You need to check the result of scanf If it fails to match, the pointer you pass in is not modified. In your specific case name would then contain arbitrary data.

You need to check the result of scanf. If it fails to match, the pointer you pass in is not modified. In your specific case, name would then contain arbitrary data.

Once you check the output of scanf, you'll see it's failing to match on that string. Scanf is not a regular expression parser. It will only attempt a match on the first "item" it sees on the input stream.

The match specifier %99help means "i want to match anything that contains the letters h, e, l, p in any order, up to 99 chars long". That's all. So it fails on the very first letter of your input ("T"), which is not in the set.

If you want to look for a string inside another string, use strstr for example. To read a whole line, if your environment has it, the easiest is to use getline.

You need the scanset to recognize all the characters you might enter. You also need to check the return from scanf() to see whether it succeeded. #include int main() { printf("Enter Something: "); char name100; if (scanf("%99Indhelp ", name)!

= 1) fprintf(stderr, "scanf() failed\n"); else printf("%s",name); return 0; } That will recognize "I need help" and many other phrases. The C standard says: If a - character is in the scanlist and is not the first, nor the second where the first character is a ^, nor the last character, the behavior is implementation-defined. In many implementations, you can use a notation such as %a-zA-Z to pick up a string of letters or spaces.

However, that is implementation-defined behaviour. That means it could do anything the implementation chooses, but the implementation must document what it does mean. The reliable way to write the scanset is: %abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ Of course, that leaves you with some issues around punctuation, not to mention accented characters; you can add both to the scanset if you wish.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions