Thread: help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    3

    Angry help

    I am new to C and can't get my program to work. What is suposed to happen is at the command line I enter my program name and one argument. For example lets call my program myprog.

    myprog 3

    now after entering that it should spit out 4 (argv[1] + 1 = 4).

    so all to gether it should look like this

    myprog 3
    4

    But it dosent do that instead it does this.

    myprog 3
    -1073742996

    Now thats not right.

    When I compile there are no errors or warnings so
    I cant figure it out. here is the source. If somenone
    could correct it then repost it that would be great
    thanks!








    ------ CODE ---------

    Code:
    #include <stdio.h>
    
    int main(int argc, int argv[])
    {
    	int hex;	
    
    	if(argc == 2)
    	{
    		hex = dec2hex(argv[1]);
    		printf("%i\n", hex);
    	}
    	else if(argc == 1)
    	{
    		printf("Error: no arguments\n");
    	}
    	else
    	{
    		printf("Error: too many arguments\n");
    	}
    
    	return 1;
    }
    
    int dec2hex(int dec)
    {
    	return dec + 1;
    }
    Last edited by markavdh; 02-26-2003 at 05:03 PM.

Popular pages Recent additions subscribe to a feed