Thread: wrong output on input

  1. #1
    Registered User
    Join Date
    May 2003

    wrong output on input

    hey, i've got (in my eyes) this weird little problem:

    #include <stdio.h>
    int main()
        char day[10];
        printf("give a day: ");
        scanf("%s", day);
        if ((day == "saturday") || (day == "sunday"))
            printf("\nIts weekend\n");
            printf("\n its a weekday");
    no matter what day I input it always returns weekday.

    some got an idea how this happens because i really dont.
    Last edited by TeQno; 06-05-2003 at 02:36 AM.

  2. #2
    Registered User
    Join Date
    Mar 2003
    You can't use '==' to compare strings (what you are actually doing is comparing to char * pointers which are never equal since they point to different things... so you always get an answer of false... so you always think its a week day)

    Try strcmp() or strncmp() which are defined in the header string.h

    edit: Salem beat me to it!

  3. #3
    Registered User
    Join Date
    May 2003


    ah thanx guys i didnt know i couldnt use == for this thing

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  2. Using SSCANF input string output two variables
    By kevndale79 in forum C Programming
    Replies: 9
    Last Post: 10-02-2006, 02:57 PM
  3. Can we input negative numbers in the output windiw
    By hitesh1511 in forum C Programming
    Replies: 1
    Last Post: 08-22-2006, 12:07 AM
  4. Trouble with a lab
    By michael- in forum C Programming
    Replies: 18
    Last Post: 12-06-2005, 11:28 PM
  5. Base converter libary
    By cdonlan in forum C++ Programming
    Replies: 22
    Last Post: 05-15-2005, 01:11 AM