简体   繁体   中英

How to extract file name from file path with sscanf_s()?

I want to extract file name License.xml from the string through function sscanf_s

Content-Disposition: form-data; name="file"; filename="C:\share\file1\License.xml"

Currently, I just know to match the whole file name by

char file_name[256] = {""};
sscanf_s( line, "Content-Disposition: form-data; name=\"file\"; filename=\"%s\"", file_name);

As for how to extract the License.xml from file name, I do not know how to do that?

From this doc , I did not find any useful information to do that.

char *line ="Content-Disposition: form-data; name=\"file\"; filename=\"C:\\share\\file1\\License.xml\"";
char file_name[256] = {""};
char *p;
sscanf_s( line, "%*s %*s %*s filename=\"%[^\"]\"", file_name, sizeof(file_name));
p = strrchr(file_name, '\\')+1;
memmove(file_name, p, strlen(p)+1);
puts(file_name);//License.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM