This is a common mistake amongst newer C/C++ developers. The scanf function detects you hitting the ENTER/RETURN key to signal the end of input, but it also catches the \n character as well at the end of the input string, so you essentially get two RETURNS being detected.
Please read up on an example of using fgets and sscanf here:
https://www.amazon.com/Primer-Plus-5th-Stephen-Prata/dp/0672...
My version was older than the Amazon version as I learned in 1987.
You declared the array wrong, correct way:
Also you cannot declare two
a
s rename the second:to something else.
Might I suggest some good C Books? I think you need to learn C before coding in it.
Reference Style - All Levels
Beginner
Intermediate
Above Intermediate
Uncategorized Additional C Programming Books
This is a common mistake amongst newer C/C++ developers. The
scanf
function detects you hitting theENTER/RETURN
key to signal the end of input, but it also catches the\n
character as well at the end of the input string, so you essentially get twoRETURNS
being detected.Please read up on an example of using
fgets
andsscanf
here:http://www.linuxforums.org/forum/programming-scripting/67560-problem-scanf.html
It will resolve this issue very quickly for you. In the meantime, I strongly urge you to check out this book:
http://www.amazon.com/Primer-Plus-5th-Stephen-Prata/dp/0672326965
It is the most commonly used C programming book in high school and colleges in North America, and has TONS of examples for you to work through, including this specific program you demonstrated above. The print version has more examples than the e-book, so I would just cough up the $30.00 for the printed version.
Good luck!