How to extract only the date part from a char* ?
char *file = "TEST_DATA_20141021_18002.zip"
char *date ="20141021"
Thanks!
How to extract only the date part from a char* ?
char *file = "TEST_DATA_20141021_18002.zip"
char *date ="20141021"
Thanks!
#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;
}