C分割字符串 sscanf vs strtok

sscanf

	char buf[]="port=5000";
	char key[100]="";
	char value[100]="";

	sscanf(buf,"%[^=]=%[^\n]",key,value);

	printf("key=%s\n",key);
	printf("value=%s\n",value);

  

strtok

	char buf[]="port=5000";
	char key[100]="";
	char value[100]="";

	strcpy(key,strtok(buf,"="));
	strcpy(value,strtok(NULL,"="));
	printf("key=%s\n",key);
	printf("value=%s\n",value);

  

你可能感兴趣的:(C分割字符串 sscanf vs strtok)