猿问

小白求问这段代码的意思

#include <unistd.h>  

#include <stdio.h>  

#include <stdlib.h>

#include <string.h>


typedef struct Eitem{

    char item[100];

}Eitem;


Eitem table[7777][70];

char line[1000];

const char *split = "~";

char sep;

int skip, i,j,k,h,count;

int opt[80];


int main(int argc, char * argv[])  

{   

    int ch;  

    while ((ch = getopt(argc, argv, "s:i:")) != -1)  

    {  

        printf("optind: %d\n", optind);  

        switch (ch) {  

        case 's':  

        sep = *optarg; 

            printf("HAVE option: -s, seperated by %s\n", optarg);  

break;  

        case 'i':  

        skip = atoi(optarg);

            printf("HAVE option: -i ");  

            printf("The argument of -i is %s\n", optarg);

            break;  

        case '?':  

            printf("Unknown option: %c\n",(char)optopt);  

break;  

        }  


    }  

for(i = optind; i < argc; i ++){

opt[i - optind] = atoi(argv[i]);

}

//check rule

if( opt[0] =='\0'){

printf("Error : you are supposed to choose fields to display ! \n");

exit(0);

}

for(i = 0; opt[i+1] != '\0'; i++){

if( opt[i] >= opt[i+1]){

printf("Error : Field numbers are supposed to be provided in increasing sequence and no repeatation !\n");

exit(0);

}

//unix input already

// scan the file and establish the table


while(fgets(line, sizeof(line), stdin)){

for(i = 0; ; i++){

if( line[i] == '\"')

count++;

if( line[i] == ',' && count%2 == 0)

line[i] = '~';

if( line[i] == '\0')

break;

}

char *str = strtok(line, split);

j = 0;

    while (str != NULL) {

        strcpy(table[k][j].item,str);

        str = strtok(NULL, split);

        j ++;

  }

  k ++;

//table already

//print

for(i = skip; table[i][0].item[0] != '\0';i++){

for(j = 0; opt[j] != '\0'; j++){

printf("%s %c ",table[i][opt[j] - 1].item,sep);

}

printf("\n");

}

}  


慕娘9373764
浏览 1586回答 1
1回答

anet

从你抄来的地方肯定有啊,不要这么懒
随时随地看视频慕课网APP
我要回答