Thread: Why Doesnt This Function Work ??

  1. #1
    Unregistered
    Guest

    Why Doesnt This Function Work ??

    PLEASE TELL ME WHATS WRONG WITH THIS



    FUNCTION PROTOTYPE// void argval (int, char*);

    FUNCTION CALL// argval(int,char*);

    FUNCTION// void argval(int argc, char* argv[])
    {

    if (argc < 3)
    {
    printf("usage : p2 input output -m -n \n");
    exit (1);
    }
    if (argc >5)
    {
    printf("usage : p2 input output -m -u \n");
    exit (1);
    }
    if((strcmp(argv[1],argv[2])==0))
    {
    printf("test\n");
    exit (1);
    }



    if(argc==4)
    {
    printf("ok\n");
    if(strcmp(argv[3], "-m")==0)
    printf("-m\n");
    else if (strcmp(argv[3], "-u")==0)
    printf("-u\n");
    else
    {
    printf("error invalid flags usage -m -u\n");
    exit(1);
    }
    }

    if(argc==5)
    {
    printf("ok\n");

    if(strcmp(argv[3], "-m")==0)
    printf("-m\n");
    else if (strcmp(argv[3], "-u")==0)
    printf("-u\n");
    else
    {
    printf("error invalid flags usage -m -u\n");
    exit(1);
    }
    if(strcmp(argv[3],argv[4])==0)
    printf("test1\n");
    else
    {
    if(strcmp(argv[4],"-m")==0)
    printf("-m\n");
    else if (strcmp(argv[4], "-u")==0)
    printf("-u\n");
    else
    {
    printf("error\n");
    exit(1);
    }
    }
    }

    if((finp=fopen(argv[1],"r"))==NULL)
    {
    printf("error\n");
    exit(1);
    }

    if((foutp=fopen(argv[2],"w"))==NULL)
    {
    printf("error\n");

    exit(1);
    }
    return;

    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What's the point of the extra flags?
    Code:
    if( argc != 5 ) {
       exit ( puts( "Invalid command line."
       "Usage: myprog.exe infile outfile -m -u" ) );
    }
    
    if( (infile=fopen( argv[1], "r" )) == NULL )
    {
       exit( perror( "Invalid input file." ) );
    }
    if( (outfile=fopen( argv[2], "w" )) == NULL )
    {
       exit( perror( "Unable to create output file." ) );
    }
    if( strcmp( argv[3], "-w" ) || strcmp( argv[4], "-u" )
    {
       exit ( puts( "Invalid command line."
       "Usage: myprog.exe infile outfile -m -u" ) );
    }
    Quzah.

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Well, first off, your prototype is wrong. char* and char*[] are not the same thing (char*[] is really char **). So you need to change that, for sure.

    How, exactly, is it called? Does the call look like this:

    Code:
    int main(int argc, char *argv[]){
    	argval(argc,argv);
    	return 0;
    }
    The above, BTW, is the correct way to call.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM