Linux练习(处理程序命令行参数)

#include 
#include 
int main(int argc,char **argv)
{
        int opt;
        while((opt=getopt(argc,argv,"if:lr"))!=-1)
        {
            switch(opt)    
            {
                    case 'i':    
                    case 'l':
                    case 'r':
                            printf("option:%c\n",opt);
                            break;
                    case 'f':
                            printf("filename:%s\n",optarg);
                            break;
                    case ':':
                            printf("option needs a value\n");
                            break;
                    case '?':
                            printf("unknown option:%c\n",optopt);
                            break;
            }
            for(;optind)    
                    printf("argument:%s\n",argv[optind]);
            exit(0);
        }
}

转载于:https://www.cnblogs.com/tiandsp/archive/2012/09/08/2676325.html

你可能感兴趣的:(Linux练习(处理程序命令行参数))