我正在嘗試從 C 中的 HTML 輸入欄位中提取數字。鑒于以下 HTTP 發布請求,如何在 num1 和 num2 子字串之后提取數字 12 和 29 并將它們相乘?
POST /test HTTP/1.1
Host: foo.example
Content-Type: application/x-www-form-urlencoded
Content-Length: 27
num1=12&num2=29
uj5u.com熱心網友回復:
如果字串仍然具有相同的形式,則可以使用 sscanf。前任:
#include <stdio.h>
int main (void)
{
char *str = "num1=12&num2=29";
int num1, num2;
if(sscanf(str, "num1=%d&num2=%d", &num1, &num2)==2)
{
printf("num1 = %d\n", num1);
printf("num2 = %d\n", num2);
}
else puts("Error");
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/512695.html
標籤:C细绳
