1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

a function that takes 3 command-line arguments

Discussion in 'C' started by new4c, Jan 6, 2008.

  1. new4c

    new4c New Member

    Joined:
    Jan 3, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    I really need help on this one. Can't believe getting this kind of question as a newbie to C programming. Thanks alot
    Write a program that takes 3 command-line arguments – the first is a flag, then second is a character, the third is a filename. If the flag argument is ‘s’ then it prints only those lines in the file that contain the character. If the flag argument is ‘-n’ then it prints only those lines in the file that do *not* contain the character.
     
  2. Mahesh.Shetye

    Mahesh.Shetye New Member

    Joined:
    Mar 22, 2008
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    0
    you shud use main(int argc, char* argv[]) function insted of main() function in your program.
     
  3. wesley001

    wesley001 New Member

    Joined:
    Jun 27, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    and for more control about argument handling you can use getopt (from GNU).
    and else like Mahesh.Shetye said:

    Code:
    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {
    if(argc!=4){
    printf("Usage: %s <flag> <char> <file>",argv[0])
    return 0;
    }
    // remaining code here
    return 0;
    }
    
     
  4. heavensgate15

    heavensgate15 New Member

    Joined:
    Mar 18, 2008
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    wow... nose bleed.... :confused:
     

Share This Page