Re: correct way to use getchar function?

  • From: ashish rohtagi <ashishrohtagi1969@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Fri, 15 Apr 2011 10:22:31 +0530

hi Jackie, sorry about the error message. but I am not encountering
any problem in compiling but in results. after I press the reply of
colour like red etc and enter the window disappears. it does not stay.
I want to stop screen. I can do it with scanf function but I want to
use getchar. I hope now I am more clear. thanks for your help. take
care, regards. ashish

On 4/15/11, Jackie McBride <abletec@xxxxxxxxx> wrote:
> Ashish:
>
> When u ask questions on list, if they pertain to an error message,
> please include the error so we can better understand what's happening.
>
> What I see a problem with is not your getchar();, but with the line
> before, e.g.,
> printf("%s's favorite color is %s\n",name,color);
> This is something a beginner c programmer might not have encountered,
> but an apostrophe has to be "escaped" with a backslash, like this:
> printf("%s\'s favorite color is %s\n",name,color);
>
> The reason for this is that apostrophes are used in C to denote a
> character, like this:
> ch = 'a';
> Thus, u have to tell the compiler that this should literally be an
> apostrophe.
>
> See if that doesn't help, ok?
>
> On 4/14/11, ashish rohtagi <ashishrohtagi1969@xxxxxxxxx> wrote:
>> hello friends, I tried to use getchar in this program, please show my
>> mistakes, as it is not working correctly. here is the code. #include
>> <stdio.h>
>>
>> int main() {
>> char name[20]; char color[20];
>>
>> printf("What is your name?"); scanf("%s",name);
>> printf("What is your favorite color?"); scanf("%s",color);
>> printf("%s's favorite color is %s\n",name,color);
>>
>>                          getchar();
>>
>>               return(0);
>> }
>> __________
>> View the list's information and change your settings at
>> //www.freelists.org/list/programmingblind
>>
>>
>
>
> --
> Blame the computer--why not? It can't defend itself & occasionally
> might even be the culprit
> Jackie McBride
> Jaws Scripting training materials:
> www.screenreaderscripting.com
> homePage: www.abletec.serverheaven.net
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
>
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: