It's working as expected. The next character is '\n', so the loop terminates immediately. You never end your string with a '\0' character, and the program prints garbage.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,483
Solved Threads: 1,407
Skill Endorsements: 54
Iam not sure about this solution..
every string is ended with null character or \n.try this block...
do
{character=getchar();
sentence[counter++]=character;
}while(character!='\n');
sentence[counter]='\0';
puts(sentence);
Arbus
Practically a Master Poster
615 posts since Dec 2010
Reputation Points: 45
Solved Threads: 31
Skill Endorsements: 0