为了账号安全,请及时绑定邮箱和手机立即绑定

小白求问这段代码的意思

小白求问这段代码的意思

慕娘9373764 2017-08-05 21:41:36
#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"); }}  
查看完整描述

1 回答

?
anet

TA贡献79条经验 获得超19个赞

从你抄来的地方肯定有啊,不要这么懒

查看完整回答
反对 回复 2017-08-05
  • 1 回答
  • 0 关注
  • 1585 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信