說明:
用sscanf解析字串給變數
用sscanf解析字串給變數
Code:
#include <stdio.h>
int main(int argc, char *argv[])
{
int width, height;
char test[] = "88x99";
printf("Input=> [%s]\n", test);
if (sscanf(test, "%dx%d", &width, &height) == 2)
printf("Output=> width:[%d], height:[%d]\n", width, height);
else
printf("sscanf fail!\n");
return 0;
}
Result:
Input=> [88x99] Output=> width:[88], height:[99]
沒有留言:
張貼留言