如何仅从char *?
中提取日期部分 char *file = "TEST_DATA_20141021_18002.zip"
char *date ="20141021"
谢谢!
答案 0 :(得分:1)
#include <stdio.h>
#include <ctype.h>
int main(){
char *file = "TEST_DATA_20141021_18002.zip";
char date[16];
char *s = file, *d = date;
while(!isdigit(*s))
++s;
do{
*d++ = *s++;
}while(isdigit(*s));
*d = 0;
puts(date);
//or
sscanf(file, "%*[^0-9]%15[0-9]", date);//0-9 : 0123456789
puts(date);
return 0;
}