stddef.h | 212 |错误:在'typedef'之前预期'=',',',';','asm'或'__attribute__'

时间:2014-06-13 21:39:40

标签: c

代码无法编译。但是我在一个文件中完全运行它。它告诉我:

stddef.h | 212 |错误:在'typedef'之前预期'=',',',';','asm'或'属性'

真正发生了什么?

Main.c文件:

#include "InvMatriz.h"
#include <stdio.h>

int main(int argc, char **argv)
{
float **A;
int n;
printf("Ingrese el tamaño de la matriz: ");
scanf("%d", &n);

A = ingresematriz(n);
mostrarmatriz(A, n);
printf("adfasd");

return 0;
}

头文件InvMatriz.h

#ifndef INVMATRIZ_H_
#define INVMATRIZ_H_

float** ingresematriz(int );
void mostrarmatriz(float**X ,int x);

#endif // INVMATRIZ_H

Ingrese Matriz.c文件

#include "InvMatriz.h"
#include <stdio.h>



float **ingresematriz(int n)
{

int i, j;

//Asigna espacio en la memoria

float **A;

A = malloc(n * sizeof (float *));
for (i = 0; i < n; i++)
{
    *(A + i) = malloc(n * sizeof(float));
}

//Pide los elementos y los guarda

for (i = 0; i < n; i++)
{
    for (j = 0; j < n; j++)
    {
        printf("Elemento [%d] [%d]:  ", i + 1, j + 1);
        scanf("%f", *(A + i) + j);
    }
}
return A;
}

Mostrar Matriz.c文件

#include "InvMatriz.h"
#include <stdio.h>

void mostrarmatriz(float **X , int x) //Porque no hace nada pero si compila?
{

int i, j;
for (i = 0; i < x; i++)
{
    for (j = 0; j < x; j++)
    {
        printf("%f        ", *(*(X + i) + j));
    }
    printf("\n");


}
}

1 个答案:

答案 0 :(得分:0)

我建议您更换包含标题的顺序:

#include <stdio.h>
#include "InvMatriz.h"

这可能无法解决问题 - 它可能会隐藏它,但无论哪种方式,它都可能以一种可能帮助您专注于真正问题的方式改变诊断。通常,在任何情况下,您都应该始终包含系统标题。

猜测我会建议您在以下后省略换行符:

#endif // INVMATRIZ_H

如果这样做,下一个包含文件的第一行将成为注释的一部分,并且可能使后续代码无效。大多数现代编译器都会警告源文件不以空行结尾。

文件包含是将一个文件的内容插入另一个文件的简单情况,并且可以在随后包含的标头中报告一个标头中的错误。毫无疑问,stddef.h是stdio.h包含的第一个文件。当你“在一个文件中完全运行”时,代码的顺序就不一样了 - 在 stdio.h之后插入的标题的内容而不是之前。