Mail Archives: djgpp/1998/07/17/12:46:25
In comp.os.msdos.djgpp "WillB" <exSite DOT Website AT btinternet DOT com> writes:
>I can't get this program to work. [...]
>
>
>*************************************PROGRAM*******************
>
>
>#include <stdio.h>
>
>int main()
>{
>
>
>char name[20];
> short age;
> char month[10];
>
> printf("hello, and welcome to my little program\n");
>
> printf("Please enter your name...\n");
> scanf("%s", name);
> printf("Please enter your age...\n");
> scanf("%i", &age);
> printf("please enter the month you were born in lowercase..\n");
> scanf("%s", month);
>
> printf("So your name is %s and your age is %i \n", name, age);
>
>if(month==january)
^^^^^^^^^^^^^^
Herein lies the problem. The '==' comparator only works for numbers. If you
want to compare strings you need to use strcmp:
if (strcmp(month, "january") == 0) ...
strcmp returns 0 for an exact match; non zero otherwise. Further details in
the online help[+]. You might also like to check out strcasecmp and strncmp
for useful variations on a theme.
Yours,
Neil
[+] Online help as in man pages, info pages or the help menus in RHIDE.
--
Neil Townsend +44 (1865) 273121 neil AT robots DOT ox DOT ac DOT uk
- Raw text -