strsep 分割字符串后,如何控制只输出部分子串
一个一百列由制表符分割的文本文件,每行读入分割后,该如何只输出第11列到最后一列的内容呢?先谢谢大家!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <regex.h>
int main(int argc,const char *argv[])
{
FILE *fp;
size_t len = 0;
char *str = NULL;
ssize_t read;
// reg compile
regex_t reg;
const char *pat = "^##";
int cflags = REG_EXTENDED | REG_NEWLINE;
int ret = regcomp(®,pat,cflags);
char err_info;
// search
const size_t nmatch = 1;
regmatch_t pmatch;
if(argc != 2)
{
fprintf(stderr,"usage: %s <src>\n",argv);
exit(1);
}
if((fp=fopen(argv,"r")) == NULL)
{
perror("fopen()");
exit(1);
}
if(ret!=0)
{
regerror(ret,®,err_info,256);
fprintf(stderr,"%s\n",err_info);
regfree(®);
exit(1);
}
char *line = NULL;
while((read = getline(&str,&len,fp)) != -1)
{
str='\0';
int reg_res=regexec(®,str,nmatch,pmatch,0);
if(reg_res == 0)
continue;
while((line = strsep(&str,"\t")) != NULL)
{
fprintf(stdout,"%s-->",line); ## 就是这里不知道该怎么处理了
}
printf("\n");
}
regfree(®);
fclose(fp);
exit(0);
}
第55行,本想标红的,结果没有变化 没人嘛?{:10_266:},我顶一下先{:10_250:} 顶一下,领币 {:10_243:} 大裤衩子 发表于 2020-6-4 17:57
没人嘛?,我顶一下先
我帮你顶 strsep是定义在哪个库里的? 顶一下,领币 顶一下{:10_254:} {:5_108:} 楼主还在?问题解决了吗?
页:
[1]