Thread: CLAs starting with...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    1

    CLAs starting with...

    Hi, I can't get this piece of code to work. I need it to print any CLAs which start with a '-'
    Would be great if you could help me out. Ta.
    This is what i have so far:

    Code:
    #include <stdio.h>
    #include <string.h>
    int main(int argc, char * argv[])
    {
    FILE * output = stdout;
    FILE * input = stdin;
    
    int count=0;
    
    for(count=0;count<argc;count++)
            {
            if (strcmp(argv[count][0],"-")==0)
                    {
                    fprintf(output,"%s\n",argv[count]);
                    }
            }
    }

  2. #2
    lfs addicted
    Join Date
    Nov 2007
    Posts
    49
    Some editing:

    Code:
    #include <stdio.h>
    
    int main(int argc, char * argv[])
    {
    
        int count;
    
        for(count=0; count<argc; count++)
        {
            if (argv[count][0] == '-')
            {
                    printf("&#37;s\n",argv[count]);
            }
        }
        return 0;
    }

  3. #3
    Devil™
    Join Date
    Oct 2007
    Location
    IIT-Kharagpur, India
    Posts
    104
    argv[count][0] is a character NOT a string..
    you are trying to compare char to a string..
    C's Motto: who cares what it means? I just compile it!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Starting programs
    By Molokai in forum C Programming
    Replies: 1
    Last Post: 04-16-2009, 10:10 AM
  2. Starting to program
    By Charmees in forum C++ Programming
    Replies: 3
    Last Post: 07-22-2008, 02:25 PM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  5. question about reading inputs starting with 0
    By jibbles in forum C Programming
    Replies: 8
    Last Post: 08-09-2004, 03:27 AM