Thread: check my errors...

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

    check my errors...

    Code:
    #include<stdio.h>
    #include<conio.h>
    main()
    {
    char month[12];
    clrscr()
    printf("input month:");
    scanf("%s",&month);
    if (month=="january")
    printf("new year"0;
    else if (month="december");
    printf("xmas");
    else 
    printf("ordinary month")
    getch();
    return(0);
    }
    it only prints error!!! y?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Because you're still using == for comparing strings, when you should be using strcmp()
    Nor are you including all the correct header files.

    > clrscr()
    This doesn't compile

    > scanf("%s",&month);
    You don't need the & when scanning into an array of char - it's a notable exception to the & rule for all scanf parameters.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    nice example

    Quote Originally Posted by rothj0hn
    Code:
    #include<stdio.h>
    #include<conio.h>       // nonstandard header
    main()                  // main returns int should be int main()
    {
    char month[12];
    clrscr()                // ??
    printf("input month:");
    scanf("%s",&month);     // no & month is a pointer already 
    if (month=="january")   // cannot compare char arrays this way use strcmp()
    printf("new year"0;     // missing ')'
    else if (month="december");  // like above
    printf("xmas");          
    else 
    printf("ordinary month")
    getch();                // nonstandard
    return(0);
    }
    it only prints error!!! y?
    Kurt

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include <string.h>
    int main()
    {
      char month[12];
      clrscr();
      
      printf("input month:");
      scanf("%s",month);
      
      if (strcmp(month,"january") == 0)
         printf("new year");
      else if (strcmp(month,"december") == 0)
         printf("xmas");
      else
         printf("ordinary month");
         
      getch(); 
      return(0);
    }
    Main has no datatype
    Missing semicolon on line 6
    Missing end parenthesis on line 10
    Extra semicolon on line 11
    Missing semicolon on line 14
    Invalid comparisons all throughout
    Excessive laziness in poster rothj0hn

    Next time use your compiler... or geez maybe even your eyes.
    Last edited by SlyMaelstrom; 02-03-2006 at 12:38 AM.
    Sent from my iPadŽ

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    There are better ways to pause before exiting. See the FAQ.

    [edit]
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    [/edit]
    Last edited by dwks; 02-03-2006 at 03:31 PM.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Header File Errors...
    By Junior89 in forum C++ Programming
    Replies: 5
    Last Post: 07-08-2007, 12:28 AM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM