is this 1 correct?!

This is a discussion on is this 1 correct?! within the C Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> #include<conio.h> main() { char month; clrscr(); printf("input month"); scanf("%s',month); if (month==january) printf("yes"); else printf("no"); getch(); return(0); }...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    14

    is this 1 correct?!

    Code:
    #include<stdio.h>
    #include<conio.h>
    main()
    {
    char month;
    clrscr();
    printf("input month");
    scanf("%s',month);
    if (month==january)
    printf("yes");
    else
    printf("no");
    getch();
    return(0);
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No for many many reasons.

    1 - You don't need conio.h. It's a nonstandard header, and for what you're using it for, you may as well just use getchar. It just happens to be in stdio.h, which you're already including anyway.

    2 - Why are you not including a return type for main? I will never understand why people decide it's fine to leave off the return type for main when they include it with all the rest of their functions. The return type for main, by the way, is an int. Nothing else.

    3 - 'month' is a single character, not more than one. That would be an array of characters.

    4 - Your call to scanf is using the scan code for a string, but you're trying to read into a single character. You either need to change what you're reading into, or use the correct scan code. Or both. Also, the arguments for scanf are all pointers. This means you need to either provide the address of a single variable as an argument, or a pointer to said variable, or the name of an array, etc.

    5 - You can't compare strings with the equality operator. Of course in this case, you don't actually have a string, so if there actually was a variable called january it would be correct. However, what you really want is:
    Code:
    if( strcmp( somearray, "january" ) == 0 )
    Of course you'll need to use the correct header for said string function.


    Quzah.
    Last edited by quzah; 02-03-2006 at 12:34 AM. Reason: copy-paste disaster
    Hope is the first step on the road to disappointment.

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,077
    check my errors...

    We already told you all of your errors and you didn't listen at all. We even rewrote your code for you. Stop with the new topics if you aren't going to take people's advice.
    Sent from my iPadŽ

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,833
    Closed for not listening to previous thread.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linux for GNU/Linux is not correct?
    By password636 in forum Linux Programming
    Replies: 8
    Last Post: 03-31-2009, 09:30 PM
  2. Is this correct : passing strings?
    By socket in forum C Programming
    Replies: 15
    Last Post: 11-25-2008, 02:03 PM
  3. correct order to insert new node?
    By campermama in forum C++ Programming
    Replies: 1
    Last Post: 06-16-2004, 08:51 PM
  4. Replies: 1
    Last Post: 05-26-2004, 01:58 AM
  5. Loop until enter correct value
    By jchanwh in forum C Programming
    Replies: 2
    Last Post: 11-27-2001, 01:23 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21