
Beginner help with strings
...
Quote:
>Here is another (maybe better) way to do this...
>int main()
>{
> char direction;
Make that int direction since getchar() can return values outside the range
of a char.
Quote:
> printf("What direction do you want to go? (N/S/W/E) ");
You should have
fflush(stdout);
here otherwise the prompt may not be displayed before the program pauses for
input.
Quote:
> direction =3D getchar ();
You have some sort of encoding turned on in your newsreader/posting software
that turns = into =3D. I recommend that you turn it off.
Quote:
> switch (direction)
> {
> case 'n':
> case 'N':
> printf ("You went North");
> break;
> case 's':
> case 'S':
> printf ("You went South\n");
> break;
> case 'w':
> case 'W':
> printf ("You went West\n");
> break;
> case 'e':
> case 'E':
> printf ("You went East\n");
> break;
> default:
> printf ("You went no where\n");
> }
> return 0;
>}
>printf and getchar are both from conio.h I think
There is no conio.h in C. These functions are declared in <stdio.h>.
...
Quote:
><BR>{
><BR> char direction[15];
><P> printf("What direction do you want to go?-->");
><BR> scanf(" %s", direction);
><P> if (direction == 'n')
><BR> {
><BR> printf("You went North.");
><BR> }
><P> return 0;
><BR>}</BLOCKQUOTE>
...
In fact you have HTML encoding turned on which causes all of this rubbish
to be included. Please turn it off ASAP.
--
-----------------------------------------
-----------------------------------------