コーデックを試しましたが、ランタイムエラーが発生しました。私のプログラムが予期せず動作を停止します
コードブロックでは、プログラムは最初の入力を要求してから、プログラムが正しく機能しなくなったというメッセージが表示されます。
また、ランタイムエラーが発生しないようにする方法を教えてください。
#include <stdio.h>
struct node
{
int data;
struct node* next;
};
struct node* head;
int main()
{
head=NULL;
int i,n,x;
printf("\nEnter the number of nodes");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the value");
scanf("%d",&x);
Insert(x);
}
printf("\nHow many numbers?\n");
Print();
return 0;
}
void Insert(x) /*To create new node in a linked list*/
{
struct node* temp=(struct node*)malloc(sizeof(struct node));
temp->data=x;
temp->next=NULL;
struct node* temp1;
temp1=head;
while(temp1->next!=NULL)
{
temp1=temp1->next;
}
temp1->next=temp;
}
void Print() /*to print the linked list*/
{
struct node* temp;
temp=head;
printf("\nThe list is");
while(temp!=NULL)
{
printf("\n%d",temp->data);
temp=temp->next;
}
printf("\n");
}
'head'は常に' NULL'ですが間違っています。 –
ちょっと、 'void Insert(x)' ?????タイプはどこですか? –
コードをデバッグしようとしましたか? –