Say I have a const char* string like this:
../products/product_code1233213/image.jpg
I want to retrieve the second last part of this path string, which is the parent folder name of the jpg file, how would I do that?
You can use strtok.
#include <string.h>
#include <stdio.h>
int main()
{
char str[] = "/products/product_code1233213/image.jpg";
char s[2] = "/";
char *token;
/* get the first token */
token = strtok(str, s);
/* walk through other tokens */
while( token != NULL )
{
printf( " %s\n", token );
token = strtok(NULL, s);
}
return(0);
}
Output:
products
product_code1233213
image.jpg
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다