Thread: Is my compiler acting up?

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    53

    Is my compiler acting up?

    When my tutorial is explaining 'char' it shows two pieces of code. I can't run either of them because I get the error "Undefined reference to WinMain@16".....

    Code:
    #include <stdio.h>
    
    int maint()
    {
        int cod;
        char c;
    
        c='a';
        cod = (int) c;
       }
    and

    Code:
    #include <stdio.h>
    
    int maint()
    {
        int cod;
        char c;
    
        cod=98;
        c= (char) cod;
       }
    The thing is, I don't really understand char, so I can't really fix it.
    Could someone please explain the pieces of code too? Thanks!

  2. #2
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    My guess if that you've created a Windows project, instead of a Windows Console project.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    53
    I never made a choice concerning a project. Though, how do I change the type of project ?

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Just to make sure though, you do have a function called main() don't you?
    http://www.bloodshed.net/faq.html#3
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Apr 2005
    Posts
    67
    add this before the last brace:

    Code:
     return 0;

  6. #6
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    You've (presumably accidentally) called your main function maint instead of main.

  7. #7
    Registered User
    Join Date
    Oct 2005
    Posts
    53
    I hate it when that happens!, I finish typing mai- and the compiler suggests maint and I press enter (I always put the brackets later for no reason whatsoever) and yeah... Thanks, now could someone please explain the code?
    Alastor

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    > Thanks, now could someone please explain the code?
    Explain what?
    I see cod, but nothing fishy about it
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    What do you want explaining?

    char and int are two C integral types. A char is one byte in size, an int is larger.

    You can assign a char to an int no problem, because every value of char will fit in an int.

    You can also assign an int to a char, as long as the value is in the appropriate range for a char.

    In C, character constants like 'a' are actually an integer of type int, not char. However, 'a' will always fit into a char also, so char c = 'a'; is fine.

    On an ASCII system, 'a' will be the int value 97, but C doesn't state that the implementation needs to be ASCII.

    Also, it is upto the implementation whether char is to be treated as a signed char, or an unsigned char.

    Any other questions?
    Last edited by cwr; 10-11-2005 at 01:15 AM.

  10. #10
    Registered User
    Join Date
    Oct 2005
    Posts
    53
    Yeah, how do you store more than once character in a variable? (With a string?)

  11. #11
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    A char array. In C, a string is a char array with a null ('\0') character at the end.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  2. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  3. C Compiler and stuff
    By pal1ndr0me in forum C Programming
    Replies: 10
    Last Post: 07-21-2006, 11:07 AM
  4. I can't get this new compiler to work.
    By Loduwijk in forum C++ Programming
    Replies: 7
    Last Post: 03-29-2006, 06:42 AM
  5. how to call a compiler?
    By castlelight in forum C Programming
    Replies: 3
    Last Post: 11-22-2005, 11:28 AM