0
嗨我想要使用來自用戶的輸入將數組的元素轉換爲整數。將字符元素從數組轉換爲int
#include <stdio.h>
#include <string.h>
int main()
{
char i[9]={'-','-','-','-','-','-','-','-','\0'};
int j;
printf ("enter an integer for an element ");
sscanf(i, "%d", &j);
return 0;
}
我讀的地方,使用的sscanf是做這件事,但我不知道使用它的正確方法。
https://linux.die.net/man/3/sscanf或'男人sscanf'在一個linux/osx機器上 – Mobius
一旦你弄明白了,注意'sscanf'的返回結果並採取相應的行動,否則就會陷入侵犯[Henry Spencer's Sixth Commandment]的坑中(http://www.seebs.net /c/10com.html)。通過輸入字符串的外觀,你將需要它。 – WhozCraig