Thread: main()

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    3

    Exclamation main()

    I am reading a book teaching me C
    I am using visual c++ 2005 edition express

    when i type the code written in the book, i get an error
    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    i dont understand it at all.

    here is the code
    /*Prints a charter and some numbers */
    #include <stdio.h>
    main()
    {
    printf("A letter grade of %c\n", 'B');
    printf("A test score of %d\n", 87);
    printf("A class average of %.1f\n", 85.9);
    return 0;
    }

    can you tell me how i can fix it? i think it has somethign to do with main()

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by kleam
    can you tell me how i can fix it? i think it has somethign to do with main()
    Get a book published after 1989? Visit the FAQ?
    FAQ > What's the difference between... > main() / void main() / int main() / int main(void) / int main(int argc, char *argv[])
    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    Compile "C" code with a C++ compiler?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    You can compile your code as C in VC++ 2005. In your project properties go to C/C++ -> Advanced -> Compile As
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Registered User
    Join Date
    Jul 2006
    Posts
    3
    well im using a c++ compiler, will that not work on c programming?

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by kleam
    well im using a c++ compiler, will that not work on c programming?
    I would say that right now it is highly recommended that you avoid extra unnecessary confusion.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Jul 2006
    Posts
    3
    thank you, now i have another problem.

    It all works now, but it goes so quickly i cant tell if what im programming is correct.

    how can i stop the compiler from closing the console?

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    By reading the FAQ. Why do people keep asking this question? We've answered it eleventy billion times. Someone needs to sticky the answer.
    Read this for some ideas: http://faq.cprogramming.com/cgi-bin/...&id=1043284385
    Which will refer you to here:
    http://faq.cprogramming.com/cgi-bin/...&id=1043284385

    Even 4chan knows this one: http://dis.4chan.org/read.php/prog/1152142735/

  8. #8
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    FAQ > How do I... (Level 1) > Stop my Windows Console from disappearing everytime I run my program?

    Edit: Beaten. And yeah, it's been answered "eleventy billion times". Though I personally like my programs executing in a blink of an eye. (Run it from the console!)
    Last edited by Cactus_Hugger; 07-31-2006 at 10:02 PM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  9. #9
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    I don't like mine executing in the blink of an eye...but of course most of my programs are Win32 ones so if it executes in the blink of an eye there's a problem with the window or the message loop . Lol from the 4chan link I found a quote I like: "Ah well. At least it's good to see that you haven't started with the java faggotry." Lol, I thought I'd share that with you guys.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  10. #10
    Registered User
    Join Date
    Sep 2005
    Posts
    85
    put an int before main

  11. #11
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    If you want to write C code I highly recommand to do the simple thing JaWiB posted.
    You can compile your code as C in VC++ 2005. In your project properties go to C/C++ -> Advanced -> Compile As
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  12. #12
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >If you want to write C code I highly recommand to do the simple thing JaWiB posted.
    Of course, we'd still tell him to use a proper declaration for main.
    My best code is written with the delete key.

  13. #13
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Compile As is bad. It overrides the settings when they probably shouldn't be overridden. Just give the file a .c ending (instead of .cxx, .cpp, .cc, or anything like that) and the environment will compile it as C by default.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why To Use int main()
    By year2038bug in forum C Programming
    Replies: 2
    Last Post: 08-19-2005, 01:28 PM
  2. passing params to main()
    By mike11 in forum C++ Programming
    Replies: 14
    Last Post: 06-21-2005, 12:36 PM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  4. Int Main or Void Main?
    By FromHolland in forum C++ Programming
    Replies: 9
    Last Post: 06-12-2003, 04:29 PM
  5. int main (), main (), main (void), int main (void) HELP!!!
    By SmokingMonkey in forum C++ Programming
    Replies: 7
    Last Post: 05-31-2003, 09:46 PM