Re: correct way to use getchar function?

  • From: Jackie McBride <abletec@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Thu, 14 Apr 2011 21:37:29 -0700

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

Other related posts: