Ami*_*ahi 6 c arrays string scanf char
我正在尝试获得一个非常大的数字(超过unsigned long long int
)。所以我把它作为一个字符串,然后一个数字一个数字地转换成整数并使用它。
#include <stdio.h>
#include <string.h>
int main()
{
char m[100];
int x;
scanf("%s",m);
for(int i=0; i<strlen(m); i++){
sscanf(m[i],"%d",&x);
printf("%d",x);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是,在编译期间它显示:
警告:传递 'sscanf' 的参数 1 使指针来自整数而不进行强制转换
和
注意:预期为“const char *restrict”,但参数的类型为“char”
而且,当我运行程序时,它会给我Segmentation fault (core dumped)
错误。
我还尝试了更简单的代码来查找问题:
#include <stdio.h>
#include <string.h>
int main()
{
char m[5];
char n;
int x;
scanf("%s",m);
n = m[1];
sscanf(n,"%d",&x);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但什么都没有改变。