Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
运行C程序时出错_C_Linux_Structure - Fatal编程技术网

运行C程序时出错

运行C程序时出错,c,linux,structure,C,Linux,Structure,我在Linux上写了一个C程序。当我编译程序时,没有错误发生,但是当我运行它时,我收到了许多错误。我的节目是, #include <stdio.h> typedef struct a{ char *name; int id; char *department; int num; } ab; int main() { ab array[2]={{"Saud",137,"Electronics",500},{"Ebad",111,"Telecom",570}}; prin

我在Linux上写了一个C程序。当我编译程序时,没有错误发生,但是当我运行它时,我收到了许多错误。我的节目是,

#include <stdio.h>

typedef struct a{
 char *name;
 int id;
 char *department;
 int num;
} ab;

int main()
{
 ab array[2]={{"Saud",137,"Electronics",500},{"Ebad",111,"Telecom",570}};
 printf("First student data:\n%s\t%d\t%s\t%d",array[0].name,array[0].id,
     array[0].department,array[0].num);

 //ab swap(&array[]);
}

要编译,您需要编写以下内容:

gcc -o newproject newproject.c
这将创建一个名为
newproject
的文件,您可以通过编写以下命令来运行该文件:

./newproject

编写
gcc./newproject
来运行您的程序没有任何意义。

您的代码在这里编译得很好。你到底是如何编译这段代码的?您确定此处显示的代码就是您实际编译的代码吗?需要共享您的makefile或您编译它的方式。代码没有问题。如果main为int,则需要返回一些int。可能是使用错误的编译器进行编译。不知道是否有帮助,但。。。你读过吗:在terminal first我写的,gcc-o newproject newproject.cThanks选择mistake@SaudFarooqui-如果问题解决了,请考虑接受。这将有助于我们大家确保问题得到解决。
./newproject