c - i cant get this program to work correctly. -
I have been asked to modify the program to read the letters instead of numbers. I modified the array in a four array. Two "% d" to "% c" has been changed to the bottom
zero principal (zero) {
four [100]; Int counter; Int b; Counter = 0; Printf ("Please enter the length of the array:"); Scanf ("% d", & amp; b); While (counter! = B) {printf ("Please enter characters:"); Scanf ("% c", and [counter]); Counter ++; } A [counter] = '\ 0'; Counter = 0; While (a [counter]! = '\ 0') {printf ("\ n"); Printf ("% c", a [counter]); Counter ++; }} When I run it, it programmatically:
Please enter the length of the array: (4)
Please enter the character: Please enter the character : (A)
Please enter characters: Please enter characters: (A)
a
a
() User input is used to indicate
Really good if i can get some help
You have to remember that input leaves the new line in the buffer, So when you read a letter
the solution is very simple: by adding one place to the format code, tell scanf to read and leave the leading white space: scanf ("% c", and [counter]); / * * * / / * | * / / * * Note space here * /
Comments
Post a Comment