分解命令行字符串


#include 
#include 
#include 

void main( void )
{
	char string[]	= "ffmpeg -i in.mp4 -i watermark1.png -filter_complex \"overlay=x=0:y=0\" -f mp4 out.mp4";
	printf("%s\n\nTokens:\n", string);

	char *szcmdline = (char *) malloc(strlen(string)+1);
	if (szcmdline == NULL) {
		return;
	}
	strcpy(szcmdline, string);

	int argc		= 0;
	char *argv[64]	= { NULL, };
	char *offset	= szcmdline;

	char seps[]		= " ,\t\n";
	char *token = strtok(offset, seps);
	while (token != NULL) {
		argv[argc++]= token;
		token[-1] = (argc == 1) ? token[-1] : '\0';
		token = strtok(NULL, seps);
	}

	for (int i=0; i



你可能感兴趣的:(C/C++)