【发布时间】:2011-04-27 05:14:12
【问题描述】:
My Char 数组允许用户输入纯数字字符串,从而将每个数字存储在其自己的数组空间中。我需要将 char 数组的每个元素分配给 int 数组中的相应位置。我如何存储实际数字而不是 ASCII 等价物
例如。如果我输入 9 作为字符串,我不想要 57(ASCII 值)而是数字 9。
int main()
{
int x[256] = {0};
int y[256] = {0};
char temp1[256] = {0};
char temp2[256] = {0};
char sum[256] = {0};
printf("Please enter a number: ");
scanf("%s", &temp1);
printf("Please enter second number: ");
scanf("%s", &temp2);
for(i=0; i<256; i++)
{
x[i] = ((int)temp1[i]);
y[i] = ((int)temp2[i]);
}
【问题讨论】: