syntax error at end of input

This is a discussion on syntax error at end of input within the C++ Programming forums, part of the General Programming Boards category; Can someone please tell we where the error in this code is i keep getting an error on the last ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    3

    syntax error at end of input

    Can someone please tell we where the error in this code is i keep getting an error on the last line saying "syntax error at end of input" need help quick please.

    Code:
    int main()
    {
    	// Welcome message
    	printf("Welcome to RoboSimoClient\n\n");
    
    	// Ask user for server IP address, then connect to it
    	int counter;
    	int a, b, c, d, port;
    	printf("Please enter server IP address: ");
    	scanf("%d.%d.%d.%d", &a, &b, &c, &d);
    	printf("Please enter port number: ");
    	scanf("%d", &port);	
    	connect_to_server(a, b, c, d, port);
    	// circle the arena
    	while(1)
    	{
    		set_motor_speeds(100,100);
    		counter = 1;
    		while(read_analog_channel(0) < 120 && read_analog_channel(1) < 120);
    		{
    			set_motor_directions(1, 1);
    		}
    		set_motor_directions(0, 0);
    		
    		if(read_analog_channel(0) > 120 && read_analog_channel(1) < 120);
    		{
    			while(counter > 0);
    			{
    				if(read_analog_channel(0) > 120 && read_analog_channel(1) < 120)
    				{
    					set_motor_directions(1, 0);
    				}
    				else
    				{
    					set_motor_directions(1, 1);	
    				}
    				counter = counter + 1;
    		}
    		
    		if(read_analog_channel(0) < 120 && read_analog_channel(1) > 120);
    		{
    			while(counter > 0);
    			{
    				if(read_analog_channel(0) < 120 && read_analog_channel(1) > 120)
    				{
    					set_motor_directions(0, 1);
    				}
    				else
    				{
    					set_motor_directions(0, 0);
    				}
    				counter = counter + 1;
    		}
    	}
    	return 1;
    }

  2. #2
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Aside from missing header stdio.h and no function defs for read_analog_channel(), etc, the biggest problem I see is the while() statement and the first if() are missing their closing braces. As such, the compiler goes off the end of the file looking for the missing braces.

    HTH

    Jeff

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    3

    Smile

    Quote Originally Posted by jeffcobb View Post
    Aside from missing header stdio.h and no function defs for read_analog_channel(), etc, the biggest problem I see is the while() statement and the first if() are missing their closing braces. As such, the compiler goes off the end of the file looking for the missing braces.

    HTH

    Jeff
    your a hero thank you so much

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Some problems were mentioned above, which may/may noe be duplicated here.

    Code:
    int main() // put "main(void)" instead
    {
        // Welcome message
        printf("Welcome to RoboSimoClient\n\n");
    
        // Ask user for server IP address, then connect to it
        int counter;
        int a, b, c, d, port;
        printf("Please enter server IP address: ");
        scanf("%d.%d.%d.%d", &a, &b, &c, &d);
        printf("Please enter port number: ");
        scanf("%d", &port);    
        connect_to_server(a, b, c, d, port); //function doesnt exist (if it does, you should have included it in your post!)
        // circle the arena
        while(1)
        {
            set_motor_speeds(100,100); // function doesnt exist
            counter = 1;
            while(read_analog_channel(0) < 120 && read_analog_channel(1) < 120); // you probably dont want this trailing semicolon; also the function your calling doesnt exist
            {
                set_motor_directions(1, 1);  // function doesnt exist
             }
            set_motor_directions(0, 0);
            
            if(read_analog_channel(0) > 120 && read_analog_channel(1) < 120); // trailing semi colon probably not wanted
            {
                while(counter > 0); // semicolon
                {
                    if(read_analog_channel(0) > 120 && read_analog_channel(1) < 120)
                    {
                        set_motor_directions(1, 0);
                    }
                    else
                    {
                        set_motor_directions(1, 1);    
                    }
                    counter = counter + 1;
               // missing close bracket
            }
            
            if(read_analog_channel(0) < 120 && read_analog_channel(1) > 120); //semi colon
            {
                while(counter > 0); // what the hell
                {
                    if(read_analog_channel(0) < 120 && read_analog_channel(1) > 120)
                    {
                        set_motor_directions(0, 1);
                    }
                    else
                    {
                        set_motor_directions(0, 0);
                    }
                    counter = counter + 1;
                // missing close bracket for while loop 
            }
        }
        return 1;
    }

  5. #5
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875

    Glad to help

    Quote Originally Posted by sauoon View Post
    your a hero thank you so much
    The easiest way to pick up on these kinds of brace-related errors is for me twofold:
    1. Don't write any function or code-block larger than a screen in length. If you need to make (say) a while() loop shorter, export the guts of it to an external function and then simply calling them from the while. For example is this not easier to catch?

    Code:
    while(some_condition)
    {
           doSomeFunction();
    }
    2. If your editor has a built-in code-formatter, use that on your entire file. That is what I used to find your issues. In Emacs it was Ctrl-Alt-|. When I did that it was obvious.

    Happy Sunday...

    Jeff
    Last edited by jeffcobb; 12-13-2009 at 05:02 PM. Reason: missed CODE tags

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,536
    This is not C++...
    I would advise to post in the proper section next time.
    Furthermore, quick help is not a good title. Don't use it. People don't hurry to your post regardless. Instead type a proper title and there is a bigger chance people will read it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Includes making me insane >.<
    By IceDane in forum C Programming
    Replies: 14
    Last Post: 04-14-2008, 10:24 AM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. How can I read until the end of an input line?
    By Bad_Scooter in forum C++ Programming
    Replies: 4
    Last Post: 07-19-2003, 09:29 PM
  5. Reading integers until end of input
    By nivo in forum C Programming
    Replies: 7
    Last Post: 10-20-2001, 04:18 PM

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