爲什麼下面的代碼輸入一個號碼放入該結構後獲得的第二scanf_s
時拋出異常。scanf_s拋出異常
這絕不代表一個完整的鏈接列表實現。
不知道如何進入下一個scanf_s
當輸入值?有任何想法嗎?
編輯:更新後的代碼與建議的解決方案,但仍獲得第一scanf_s
代碼後AccessViolationException
:
struct node
{
char name[20];
int age;
float height;
node *nxt;
};
int FillInLinkedList(node* temp)
{
int result;
temp = new node;
printf("Please enter name of the person");
result = scanf_s("%s", temp->name);
printf("Please enter persons age");
result = scanf_s("%d", &temp->age); // Exception here...
printf("Please enter persons height");
result = scanf_s("%f", &temp->height);
temp->nxt = NULL;
if (result >0)
return 1;
else return 0;
}
// calling code
int main(array<System::String ^> ^args)
{
node temp;
FillInLinkedList(&temp);
...
你正在使用託管代碼,你爲什麼搞亂scanf()?使用Console :: ReadLine(),int :: TryParse()和List。 –
2010-02-28 12:07:23