codechef에서 시도했지만 런타임 오류가 발생했습니다.내 프로그램이 예기치 않게 작동을 멈 춥니 다.
코드 블럭에서 프로그램은 첫 번째 입력을 요구 한 다음 프로그램이 올바르게 작동하지 않는다고 말합니다.
그리고 런타임 오류가 발생하지 않도록하는 방법은 무엇입니까?
#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)'????? 유형은 어디 있습니까? –
코드를 디버깅하려고 했습니까? –