pointers on c 十三章 13.5
程序员文章站
2022-03-11 18:21:58
...
#include <stdio.h>
#include<string.h>
#define NUL 0
char ** do_args(int arfc, char **argv,char *control,
void (*do_arg)(int ch,char *value),
void (*illegal_arg)(int ch) ){
char *temp;
char *index;
char * token;
int ch; //Save **arg to compare '-'
for(temp = *++argv; *temp != NUL && *temp == '-';){
ch= *++temp;// - last char
if( (index = strchr(control,ch) ) ){
switch( *++index){//index 指向control对应字符后面那个字符
case '+' :// 就有对应的值
if(*++temp != ' '){
token = strtok(control," ") ; //分隔字符串
do_arg(ch,temp);
temp = strtok(NULL," "); //定位到下一个空格处
}
else {
while(*temp++==' ');
token = strtok(temp," ") ;
do_arg(ch,token);
temp = strtok(NULL," ");
}
break;
default:
do_arg(ch,NULL);
}
}
else
illegal_arg(ch);
temp++;
}
return ++argv;
}
不知道对不对555
上一篇: Two Pointers
下一篇: Tow Pointers