getopt

This is a discussion on getopt within the C Programming forums, part of the General Programming Boards category; Im new to getopt(), I have never used it before and i was just wondering what I am doing wrong ...

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    69

    getopt

    Im new to getopt(), I have never used it before and i was just wondering what I am doing wrong here. Here is my code so far....

    compiler error
    Code:
    [cat]$ make
    gcc -Wall -ansi -pedantic kitty.c -o cat
    kitty.c: In function ‚main‚:
    kitty.c:11: warning: implicit declaration of function ‚getopt‚
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <string.h>
    
    int main(int argc, char * argv[])
    {
            char choice;
    
            /*FILE * fptr;*/
            while (( choice = getopt (argc, argv[1], "AbeEnstTuv")) != -1)
            {
    
                    switch(choice)
                    {
                            case 'A':
                            printf("show all\n");
                            break;
    
                            case 'b':
                            printf("number nonempty output lines\n");
                            break;
    
                            case 'e':
                            printf("equivalent to -vE\n");
                            break;
    
                            case 'E':
                            printf("displays $ at end of each line\n");
                            break;
    
                            case 'n':
                            printf("number all output lines\n");
                            break;
    
                            case 's':
                            printf("supress repeated empty output lines");
                            break;
    
                            case 't':
                            printf("equivalent to -vT");
                            break;
    
                            case 'T':
                            printf("display TAB character as ^I");
                            break;
    
                            case 'u':
                            printf("ignored");
                            break;
    
                            case 'v':
                            printf("use ^ and M- notation, except for LFD and TAB");
                            break;
    
                            default:
                            fprintf(stderr, "%s is not a valid character", &choice);
                            exit(1);
                    }
            }
            return 0;
    }

  2. #2
    Registered User
    Join Date
    Jan 2010
    Posts
    69
    actually i figured out that i was missing an include at the top.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getopt option arguments
    By erasm in forum C Programming
    Replies: 4
    Last Post: 08-08-2009, 07:42 AM
  2. getopt help
    By wuzzo87 in forum C Programming
    Replies: 12
    Last Post: 04-09-2007, 03:16 AM
  3. getopt and multiple options
    By bej in forum Linux Programming
    Replies: 2
    Last Post: 11-17-2005, 03:51 PM
  4. write a loop to a file, getopt()
    By kristy in forum C Programming
    Replies: 3
    Last Post: 08-15-2003, 03:57 PM
  5. getopt() and weird output
    By kristy in forum C Programming
    Replies: 2
    Last Post: 06-28-2003, 04:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21