鱼C论坛

 找回密码
 立即注册
查看: 2142|回复: 8

[已解决]请教一下各位大神,为什么编译不了

[复制链接]
发表于 2018-4-22 15:17:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
//按照编译提示的错误找了,但是还是不知道错误在哪哦,自学的新手菜鸟,请教各位大神

#include<stdio.h>
#include<stdlib.h>
#define N 41
typedef struct LNode
{
      int data;
      int num;
      struct LNode * next;
}LNode, * pointer;

pointer  create(int n)
{
      pointer p = NULL, head, k;
      int i=1;
      head = (pointer)malloc(sizeof(LNode));
      p = head;
      if( n != 0 )
      {
            while(i <= n)
            {
                  k = (pointer)malloc(sizeof(LNode));
                  k->data = i++;
                  k->num = rand()%100;
                  p->next = k;
                  p = k;
            }
            k->next = head->next;
            free(head);
            return (k->next);
}
      
int main()
{
      int n = N, m, i;
      pointer p = create(n), temp;
      m = p->num;
      while( p != p->next)
      {
            for(i=1; i<m; i++)
                  p = p->next;
            printf("%d-->",p->next->data);
            m = p->next->num;
            temp = p->next;
            p->next = temp->next;
            free(temp);
            p = p->next;
      }
      printf("%d",p->data);
      return 0;
}
最佳答案
2018-4-22 15:38:30
create函数return前少个花括号"}"吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2018-4-22 15:26:44 | 显示全部楼层
各位走过路过的大神,帮忙指点一下,跪拜
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-4-22 15:38:30 | 显示全部楼层    本楼为最佳答案   
create函数return前少个花括号"}"吧
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-4-22 15:59:12 | 显示全部楼层
这是链表 ?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-4-22 21:50:10 | 显示全部楼层
LordHdy 发表于 2018-4-22 15:38
create函数return前少个花括号"}"吧

好像是少一个,谢谢了。 花括号我都是成对打的呀,奇了怪了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-4-22 21:50:50 | 显示全部楼层

恩啊,小甲鱼老师布置的那个作业
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-4-22 22:01:12 | 显示全部楼层
LordHdy 发表于 2018-4-22 15:38
create函数return前少个花括号"}"吧

加了花括号还是不行
Compiling...
约瑟夫.c
E:\VC程序\约瑟夫问题\约瑟夫.c(16) : error C2275: 'Node' : illegal use of this type as an expression
        E:\VC程序\约瑟夫问题\约瑟夫.c(9) : see declaration of 'Node'
E:\VC程序\约瑟夫问题\约瑟夫.c(16) : error C2146: syntax error : missing ';' before identifier 'k'
E:\VC程序\约瑟夫问题\约瑟夫.c(16) : error C2065: 'k' : undeclared identifier
E:\VC程序\约瑟夫问题\约瑟夫.c(17) : error C2143: syntax error : missing ';' before 'type'
E:\VC程序\约瑟夫问题\约瑟夫.c(20) : error C2065: 'i' : undeclared identifier
E:\VC程序\约瑟夫问题\约瑟夫.c(22) : warning C4047: '=' : 'int ' differs in levels of indirection from 'struct LNode *'
E:\VC程序\约瑟夫问题\约瑟夫.c(23) : error C2223: left of '->data' must point to struct/union
E:\VC程序\约瑟夫问题\约瑟夫.c(24) : error C2223: left of '->num' must point to struct/union
E:\VC程序\约瑟夫问题\约瑟夫.c(25) : warning C4047: '=' : 'struct LNode *' differs in levels of indirection from 'int '
E:\VC程序\约瑟夫问题\约瑟夫.c(26) : warning C4047: '=' : 'struct LNode *' differs in levels of indirection from 'int '
E:\VC程序\约瑟夫问题\约瑟夫.c(28) : error C2223: left of '->next' must point to struct/union
E:\VC程序\约瑟夫问题\约瑟夫.c(31) : error C2223: left of '->next' must point to struct/union
E:\VC程序\约瑟夫问题\约瑟夫.c(31) : warning C4033: 'create' must return a value
执行 cl.exe 时出错.

约瑟夫.obj - 1 error(s), 0 warning(s)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-4-27 21:57:52 | 显示全部楼层
NILL_X 发表于 2018-4-22 22:01
加了花括号还是不行
Compiling...
约瑟夫.c

我用Visual C++6.0的可以运行呀
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-5-1 20:51:35 | 显示全部楼层
NILL_X 发表于 2018-4-22 21:50
恩啊,小甲鱼老师布置的那个作业

我抄,不是吧,都是按时完成作业的三好学生啊。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-24 12:13

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表