我只是想将 4 个命令行参数放入 4 个 int 中。它适用于第一个参数,但其余部分返回 0 我似乎看不出我做错了什么。
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
char* pEnd;
long li1, li2, li3, li4;
li1 = strtol(argv[1],&pEnd,10);
li2 = strtol(pEnd,&pEnd,10);
li3 = strtol(pEnd,&pEnd,10);
li4 = strtol(pEnd,NULL,10);
例如,如果我将程序运行为./a.out -5 5 3 9
,则解析值为-5 0 0 0
。