Thread: Too many arguments to function int main?

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    23

    Question Too many arguments to function int main?

    Using the wxDevcpp compiler to compile an example in Brian Overlands "C++ Without Fear" I get the error and message-------

    "8 H:\Dev-Cpp\MyFilesPractice_Projects\Practice482906.cpp too many arguments to function `int main()' "

    I have carefully followed the example in the book and for the life of me
    can`t figure out why I`m getting this..Any suggestions?
    Thanks, Plain

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    You shouldn't be calling main at all. Can you post the code for those of us who don't have that book handy?
    My best code is written with the delete key.

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Ah... the good ol' Brian Overlands "C++ Without Fear" example... We all know it by heart here... in fact, it's part of our credo... Why don't you post at least one line of code. Specifically the line with the error.

    If you're calling main, then don't do that and I have trouble believing that's in the example.

    EDIT: See this is why you don't spend 8 minutes looking for a synonym for "credo"
    Last edited by SlyMaelstrom; 08-29-2006 at 03:32 PM.
    Sent from my iPadŽ

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    23

    Smile too many

    Here is the code: I hope not knowing exactly how to post code will not be a hinderance.....


    Code:
    #include <iostream>
    #include <string.h>
    using namespace std;
    
    int get_a_string(char *buffer, char *s, int start);
    char strs[10][100];
    
    int main() {
    	int i;
    	int n;
    	int pos = 0;
    	char buffer[200];
    	cout << "Enter strings, separated by commas,";
    	cout << endl << "and press ENTER: ";
    	cin.getline(buffer, 199);
    	for (i = 0; i < 10; i++) {
                pos = get_a_string(buffer, strs[i], pos);
                if (pos == -1)
                break;
                }
         if (i == 11)
         n = 10;
         else 
         n = i;
         cout << n << " strings were read." << endl;
         for (int i = 0; i < n; i++)
         cout << strs[i] << endl;
         
         system ("PAUSE");     
         return 0;
    }
    
    //Get-a-string function.
    //Starting at position "start," read next substring
    //from buffer into target string s.
    //Return position of first unread character;
    //return -1 if there are no characters to read.
    //
    int get_a_string(char *buffer, char *dest, int pos) {
        int i = pos, j = 0;
        //"Consume" initial comma and blank space(s).
        while (buffer[i] == ',' || buffer[i] == ' ')
        i++;
        //Return -1 if at end of buffer.
        if (buffer[i] == '\0')
        return -1;
        //Read characters into target string, until 
        //comma or end-of-string encountered.
        while (buffer[i] != ',' && buffer[i] != '\0')
        dest[j++] = buffer[i++];
        //Terminate target string and return position
        //of first unread character.
        main(dest[j] = '\0')
        return i;
    }
    I threw the "system("PAUSE")" in there so I can beat my chest a little when I`m successful --- before the window disappears...typically the compiler doesn`t gag on this line so I wouldn`t think that was it. To satisfy myself I removed it once, recompiled, and got the same message.

    I`ve never coded before and this is my first book so you know my level of inproficiency...

    Plain
    Last edited by Ken Fitlike; 08-29-2006 at 04:08 PM. Reason: added code tags

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Use code tags. It's that simple.

    tada!
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    main(dest[j] = '\0')
    Are you sure you copied that correctly?
    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

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    23
    Sorry for the gobbledygook. I will try a code tag approach...if I know how.

    Code:
    #include <iostream>
    #include <string.h>
    using namespace std;
    
    int get_a_string(char *buffer, char *s, int start);
    char strs[10][100];
    
    int main() {
    	int i;
    	int n;
    	int pos = 0;
    	char buffer[200];
    	cout << "Enter strings, separated by commas,";
    	cout << endl << "and press ENTER: ";
    	cin.getline(buffer, 199);
    	for (i = 0; i < 10; i++) {
                pos = get_a_string(buffer, strs[i], pos);
                if (pos == -1)
                break;
                }
         if (i == 11)
         n = 10;
         else 
         n = i;
         cout << n << " strings were read." << endl;
         for (int i = 0; i < n; i++)
         cout << strs[i] << endl;
         
         system ("PAUSE");     
         return 0;
    }
    
    //Get-a-string function.
    //Starting at position "start," read next substring
    //from buffer into target string s.
    //Return position of first unread character;
    //return -1 if there are no characters to read.
    //
    
    int get_a_string(char *buffer, char *dest, int pos) {
        int i = pos, j = 0;
    
        //"Consume" initial comma and blank space(s).
    
        while (buffer[i] == ',' || buffer[i] == ' ')
        i++;
    
        //Return -1 if at end of buffer.
    
        if (buffer[i] == '\0')
        return -1;
    
        //Read characters into target string, until 
        //comma or end-ofstring encountered.
    
        while (buffer[i] != ',' && buffer[i] != '\0')
        dest[j++] = buffer[i++];
    
        //Terminate target string and return position
        //of first unread character.
    
        main(dest[j] = '\0')
        return i;
    }
    Yes, I copied this from the book, have relooked at it several times and this is from the compiler IDE.
    Previewing my post it is obvious that in my case providing code tags is not "that simple". I added the spacing before and after comments this time so it wouldn`t be as nasty. As I said this is my first language and my first book. I read the coding instructions before posting but it seems they are not simple enough for me to understand, then, after wading in confusion for a while I stumbled upon the solution. First I put code and /code in quotes, then without quotes and only the colon in front of code, then with brackets then without the colon and success. You might gather my level of inexperience from the above foray. My apologies.

  8. #8
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    That's from the book, eh?

    Well, your problem is that you're missing a lighter... go out and buy one... then burn that book.
    Sent from my iPadŽ

  9. #9
    Registered User Osaou's Avatar
    Join Date
    Nov 2004
    Location
    Stockholm, Sweden
    Posts
    69
    Amagad... <iostream>, then <string.h>... And the mess...
    This book belong with the bible, in a dumpster.

  10. #10
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by Osaou
    This book belong with the bible, in a dumpster.
    As non-religious as I am, I think that was hardly necessary.
    Sent from my iPadŽ

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> main(dest[j] = '\0')
    Again, are you sure that main is supposed to be there? If it is in the book then the book made a typo.

    That book really is not a good C++ book for beginners (or for anybody) despite the recommendation of the main site. It doesn't teach modern C++, and so it ends up leaving you with bad habits that need to be broken later in your learning. Unfortunately, most beginner C++ books do the same thing, and the only one I know of that doesn't is more accelerated than it appears you are ready for.

  12. #12
    Registered User
    Join Date
    Aug 2006
    Posts
    23
    Yuk, Yuk................page 181 "lexi.cpp".

    Since I`ve been trying for about 4 hours now to get this squeezed through the compiler, burning is far down the stack. That aside though, the only difference I can see in this and other examples in this same chapter is the character strings declaration is before not after int main(). A puzzle......

  13. #13
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I don't have the book. What does page 181 say? The fix is simple. Remove the "main(" and ")" on the line of code that was mentioned by CornedBee, then add a semi-colon.

    The "more accelerated than you are ready for" comment was not an insult. The book I was referring to isn't really meant for true programming beginners.

  14. #14
    Registered User
    Join Date
    Aug 2006
    Posts
    23

    main

    main, main???? How did that get in there? Now you see why I need help. The more I look the less I see. I wasn`t insulted by anything, I appreciate you guys patience. Now I can get on with my life! Have a good one! ....Plain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  3. newbie needs help with code
    By compudude86 in forum C Programming
    Replies: 6
    Last Post: 07-23-2006, 08:54 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Replies: 4
    Last Post: 11-23-2003, 07:15 AM