我的目标是将像 "A1234"
这样的字符串转换为值为 1234
的long
类型。 我的第一步是将 "1234"
转换为 long
,并且这正如预期的那样工作:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
char* test = "1234";
long val = strtol(test,NULL,10);
char output[20];
sprintf(output,"Value: %Ld",val);
printf("%s\r\n",output);
return 0;
}
现在我在使用指针时遇到了麻烦,并尝试忽略字符串开头的 "A"。我已经尝试了
char* test = "A1234"; long val = strtol(test[1],NULL,10);
但是程序崩溃了。
请问如何正确设置以便将其指向正确的位置?