Thread: find at least 4 errors

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    26

    find at least 4 errors

    I need help to find at least 4 errors in the following program;


    Code:
    #include <stdio.h>
    
    int main( int argc, int argv[])
    {
    	int i;
    	int a;
    	
    	for ( i = 0; i<argc, i++ )
    		printf( "%x \n", argv[i]);
    	scanf("%d", a);
    	 
    	}

    Errors highlighted in red - I have found;


    Code:
    #include <stdio.h>
    
    int main( int argc, int argv[]){
    
    	int i;
    	int a;
    	
    	for ( i = 0; i<argc; i++ );
    		printf( "%x \n", argv[i]);
    	scanf("%d", &a);
    
    	return 0;
    	 
    	}
    Can you spot anymore?

    output of the program is zero.

  2. #2
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    for ( i = 0; i<argc; i++ );
    For loops dont require a semicolon after them, that was not an error. Its looping through all the command line arguments and printing them out in hex. Which you might want to think about. Also look at your function prototype. Anything look odd ?
    Spidey out!

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    26
    Quote Originally Posted by Spidey View Post
    For loops dont require a semicolon after them, that was not an error. Its looping through all the command line arguments and printing them out in hex. Which you might want to think about. Also look at your function prototype. Anything look odd ?
    I would appreciate it if you would just tell me, whats missing?

  4. #4
    Registered User
    Join Date
    Jul 2009
    Posts
    26
    Is it the parameter of argv to contain the strings which is [i]?

    Code:
    #include <stdio.h>
    
    int main( int argc, int argv[ i ]){
    
    	int i;
    	int a;
    	
    	for ( i = 0; i<argc; i++ )
    		printf( "%x \n", argv[i]);
    	scanf("%d", &a);
    
    	return 0;
    	 
    	}

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Lego_TeCh
    Is it the parameter of argv to contain the strings which is [i]?
    No, that would be introducing another mistake. Think of its type.

    It may or may not be an error to not explicitly return 0 in the main function (it is not an error with respect to the 1999 edition of the C standard).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    Quote Originally Posted by Lego_TeCh View Post
    I would appreciate it if you would just tell me, whats missing?
    Try figuring it out yourself. Like laserlight said, think of its type.
    Spidey out!

  7. #7
    Registered User
    Join Date
    Jul 2009
    Posts
    26
    is it the void function or #include <unistd.h>?

  8. #8
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by Lego_TeCh View Post
    is it the void function or #include <unistd.h>?
    You don't have a void function. Search the internet for the proper way to declare the main() function in C.

  9. #9
    Registered User
    Join Date
    Jul 2009
    Posts
    26
    Seems like nobody knows.

  10. #10
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Posts
    285
    Quote Originally Posted by Lego_TeCh View Post
    Seems like nobody knows.
    Yep, Seems like it.
    Maybe you should try doing your homework yourself.
    Spidey out!

  11. #11
    Registered User
    Join Date
    Jul 2009
    Posts
    26
    Quote Originally Posted by Spidey View Post
    Yep, Seems like it.
    Maybe you should try doing your homework yourself.
    Why the arrogance! eewww

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Lego_TeCh
    Seems like nobody knows.
    I wonder how you managed to conclude that when I hinted that I know exactly what the answer is by telling you to think of its type. By "it" I mean argv.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I need help to find at least 4 errors in the following program;
    Since the compiler normally tells you where the 4 errors would be I'm assuming this is homework.

    Put the code in a compiler and compile it. You will see all the errors you need.

  14. #14
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Seems like nobody knows.
    What's funny is if you type "main function" into google, and hit "I'm feeling lucky", it will give you the answer. Nobody likes someone who can't think for them self, that's why no one is giving you the answer.

  15. #15
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Seems like nobody knows.
    More like nobody cares. Do your own work.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  3. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM
  4. cant find the errors.
    By sscook69 in forum C++ Programming
    Replies: 2
    Last Post: 09-10-2001, 04:26 PM