How come this doesnt work?

This is a discussion on How come this doesnt work? within the C Programming forums, part of the General Programming Boards category; #include<stdio.h> enum day {sun, mon, tue, wed, thu, fri, sat}; int main() { typedef enum day day; return 0; } ...

  1. #1
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    How come this doesnt work?

    #include<stdio.h>

    enum day {sun, mon, tue, wed, thu, fri, sat};

    int main()
    {
    typedef enum day day;
    return 0;
    }


    day find_next_day(day d)
    {
    day next_day;

    switch (d) {
    case sun:
    next_day = mon;
    break;
    case mon:
    next_day = tue;
    break;
    case tue:
    next_day = wed;
    break;
    case wed:
    next_day = thu;
    break;
    case thu:
    next_day = fri;
    break;
    case fri:
    next_day = sat;
    break;
    }
    return next_day;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    re: why doesn't this work?
    int main()
    {
    typedef enum day day;
    return 0;
    }
    1) You have a enum of day that you're typedef-ing to something of the same exact name. This is bad form.

    2) You don't actually call any functions in main.

    3) Your typedef is inside main, but you try and use it in the next function:

    day find_next_day(day d)
    {
    day next_day;
    That's why it doesn't work.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    45
    It appears that "day find_next_day(day d)" is supposed to be some sort of function that you want to do something with, but you haven't established a prototype anywhere in your code, nor have you told function main what you want to do with your function day.

    Perhaps you could:

    #include<stdio.h>

    //enumerate day out here so both main and day can see it

    enum day {sun, mon, tue, wed, thu, fri, sat};

    //function prototype

    day find_next_day(day d);

    int main()
    {

    typedef enum day day;

    //call your function here to do something with it

    return 0;

    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM

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