gpt4 book ai didi

c - 错误 : ‘::main’ must return ‘int’ void main(), 错误 : ‘strcmp’ was not declared in this scope z = strcmp(ch, ch1)?

转载 作者:行者123 更新时间:2023-11-30 19:08:25 27 4
gpt4 key购买 nike

我必须生成一个反向链表,这些是我的先决条件

定义结构:

struct node
{
int data;
struct node * link;
}

包含函数

append --- 在链表末尾添加数据。

Reverse --- 反转链表。

显示---显示链表中的所有数据。

void append ( struct node **, int ) ;

void display ( struct node * ) ;

void reverse (struct node **);

我收到的错误:

1.‘::main’ must return ‘int’
void main()

2.‘strcmp’ was not declared in this scope
z = strcmp(ch,ch1);

我的代码:

#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *link;
};
void append(struct node **head);
void reverse(struct node **head);
void display(struct node *p);
void main()
{
struct node *p = NULL;
append(&p);
printf("The elements in the linked list are: ");
display(p);
printf("The elements in the reversed linked list are: ");
reverse(&p);
display(p);
}
void reverse(struct node **head)
{
struct node *p,*q,*r;
p=q=r=*head;
p = p->link->link;
q = q->link;
r->link = NULL;
q->link = r;
while(p != NULL)
{
r = q;
q = p;
p = p->link;
q->link = r;
}
*head = q;
}
void append(struct node **head)
{
int c,z;
char ch[10] = "Yes";
char ch1[10];
struct node *temp,*rear;
do
{
printf("Enter the value:\n");
scanf("%d",&c);
temp = (struct node*)malloc(sizeof(struct node));
temp->data=c;
temp->link=NULL;
if(*head == NULL)
{
*head = temp;
}
else
{
rear->link = temp;
}
rear = temp;
printf("\nDo you want to add another node? Type Yes/No\n");
scanf("%s",ch1);
z = strcmp(ch,ch1);
}
while(z == 0);
printf("\n");
}
void display(struct node *p)
{
while(p != NULL)
{
printf("%d ",p->data);
p=p->link;
}
printf("\n");
}

最佳答案

更改void main()int main(void)并添加#include <string.h>

main() 的有效签名是

  1. int main(int argc, char **argv);
  2. int main(void);

strcmp() (以及所有 str* 函数)在 string.h 中声明)。

关于c - 错误 : ‘::main’ must return ‘int’ void main(), 错误 : ‘strcmp’ was not declared in this scope z = strcmp(ch, ch1)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45243727/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com