嵌套函数被禁用

时间:2013-10-10 20:39:47

标签: c

我在这段代码中有两个不同的编译错误,两者都位于main中。

main.c:50:错误:禁用嵌套函数,使用-fnested-functions重新启用 main.c:72:错误:输入结束时的预期声明或声明

我错过了什么?

非常感谢!

#include <stdio.h>
#include <stdlib.h>

int     ft_putline(int h, int l, int type)
{
    int     i;
    int     x;

    i = 0;

    x = 0; 

while(type == 1) /* Cette boucle affiche la première et la dernière ligne.*/
{
     if(i == 0)
    {
        printf("o");
        i++;
     }

    else if(i != 0 && i < l)
    {
        printf("-");
        i++;
    }
    else if(i == l)
     { 
        printf("o");
        printf("\n");
        type = type - 1;

     }

while(type == 0 && x >= h - (h - 1) && x <= h - 1) 

 {
    i = 0;

    x = 0;

    if(i = 0) 
    {
        printf("|");
        i++;
    }   
 }      

}

int     main()
{

int     l;
int     type; 
int     h;

l = 0;

type = 1;

h = 0;

printf("quelle est la largeur du rectangle ?\n");

scanf("%d", &h);

printf("quelle est la hauteur du rectangle ?\n");

scanf("%d", &l);


return (0);
}   

2 个答案:

答案 0 :(得分:2)

你需要另一个大括号}

你可以把它

1)就在main函数之前。

2)就在while(type == 0之前。

这里有两节课:

  • 如果您缩进代码,问题就显而易见了 正常。

  • 没有任何程序评论,我无法破译你的意图。

无论哪种方式都可以让您的代码进行编译,但运行时效果却非常不同。

答案 1 :(得分:2)

while中的第一个ft_putline()循环未正确终止,因此main()似乎位于ft_putline()内。