c语言,如何读取逗号分隔的字符串,将逗号间的字符串分别提取出来。

2020-07-04 教育 273阅读
先将所有的读进来存在一个字符串中,然后用字符分割函数strtok()//具体可参见API
例如:
char str[] = "now # is the time for all # good men to come to the # aid of their country";
char delims[] = "#";
char *result = NULL;
result = strtok( str, delims );
while( result != NULL ) {
printf( "result is \"%s\"\n", result );
result = strtok( NULL, delims );
}
以上代码的运行结果是:
result is "now "
result is " is the time for all "
result is " good men to come to the "
result is " aid of their country"
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com