Thread: argc and argv

  1. #1
    Unregistered
    Guest

    Unhappy argc and argv

    I am trying to write a program that takes 4 parameters. filename, line to start reading, line to end reading, and a keyword to match in the file. The output should give how many found per line and how many in the whole file.

    This is what I got to now, Help please, I'm lost here, and yes, it is an assignment for school...

    nt main(int argc, char *argv[])
    {
    if(argc != 5)
    {
    cout<<"Could not run program, quiting:"<<endl;

    exit(0);
    }

    ifstream fin(argv[1]); //file open

    if(fin.fail())
    {

    cout << " Failed to open input file!\n";

    exit(1);
    }

    int line_start = atoi(argv[2]);
    int line_total = atoi(argv[3]);



    char let;
    int ls = 1, tl = 1;
    while(!fin.eof())
    {

    int line = 1, total = 1;
    for(int i =1;i < line_start; i++)
    {

    for(int x=line_start; x<=line_total;x++)
    {
    fin>>let;
    cout<<let;
    }
    if(strcmp(let, arg[4]) == 0);
    line++;
    cout<<"line"<<line<<endl;

    }
    if(strcmp(let, arg[4]) == 0);
    total++;
    cout<<"total"<<total<<endl;
    }


    system("PAUSE");
    return 0;
    }

  2. #2
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    What are you lost on? Having trouble with?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help getting a grib on argc and argv
    By elwad in forum C Programming
    Replies: 10
    Last Post: 05-01-2009, 10:13 AM
  2. Using argc and argv data
    By Rad_Turnip in forum C Programming
    Replies: 4
    Last Post: 03-31-2006, 06:09 AM
  3. Converting a argc / argv construct into a va_list
    By chambece in forum C Programming
    Replies: 6
    Last Post: 07-03-2005, 04:47 PM
  4. argc & argv
    By miryellis in forum C Programming
    Replies: 11
    Last Post: 09-19-2004, 11:59 PM
  5. how do i? re: argc - argv
    By luigi40 in forum C Programming
    Replies: 2
    Last Post: 06-11-2004, 10:17 AM