我编了一个十分简单的有关结构体的C语言程序,怎么出错的,看不懂解释,结构体怎么赋值的啊?请求帮助!!

#include <stdio.h>
struct d
{
int b;
}
main()
{
int i;
struct d a[2];
for(i=0;i<2;i++)
{
scanf("%d",&a[i].b);
}
getch();
}

1>------ 已启动生成: 项目: 10080220.c, 配置: Debug Win32 ------
1>生成启动时间为 2010/12/23 18:55:37。
1>InitializeBuildStatus:
1> 正在对“Debug\10080220.c.unsuccessfulbuild”执行 Touch 任务。
1>ClCompile:
1> 8.cpp
1>c:\users\jiyuan\documents\我的文档\文件\10080220.c\10080220.c\8.cpp(12): warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(304) : 参见“scanf”的声明
1>c:\users\jiyuan\documents\我的文档\文件\10080220.c\10080220.c\8.cpp(14): warning C4013: “getch”未定义;假设外部返回 int
1>ManifestResourceCompile:
1> 所有输出均为最新。
1>8.obj : error LNK2005: _main 已经在 1.obj 中定义
1>C:\Users\jiyuan\Documents\我的文档\文件\10080220.c\Debug\10080220.c.exe : fatal error LNK1169: 找到一个或多个多重定义的符号
1>
1>生成失败。
1>
1>已用时间 00:00:00.77
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
scanf("%d",&a[i].b);--------------------不是赋值语句吗???
我加了 ; 了,还有#include<conio.h>,但还是报同样的错!!!
哎,悲剧啊!!!

该工程里面是否有多个C文件,把不需要的去掉,从报错信息来看存在两个或以上main函数
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-12-23
#include <stdio.h>
struct d
{
int b;
};/*这里少了一个分号*/
main()
{
int i;
struct d a[2];
for(i=0;i<2;i++)
{
scanf("%d",&a[i].b);
}
getch();
}
第2个回答  2010-12-23
程序中应包含 getch() 所在的库,即应加上一句:#include <conio.h>
定义结构体最后应有分号,即
struct d
{
int b;
};
第3个回答  2010-12-24
#include <stdio.h>
struct pcb_type
{
int id;
char name[5];
int priority;
char state[5];
};
void main()
{
void list(struct pcb_type pcb);

struct pcb_type pcb[10], *p;
int i;
for(i=1,p=pcb;i<=10;p++,i++)
{
printf("Please input the date of pcb[%d]:\n",i);
scanf("%d\n%s\n%d\n%s",&(p->id),&(p->name),&(p->priority),&(p->state));
}
for(i=1;i<=10;i++)
list(pcb[i]);
}
void list(pcb)
struct pcb_type pcb;
{
printf("%d%s%d%s",pcb.id,pcb.name,pcb.priority,pcb.state);
printf("inputting complete!\n");
}

我用VC编译的可以运行!
第4个回答  2010-12-23
用getch();你在程序开头加上头文件#include<conio.h>看下
第5个回答  2010-12-23
你好像没有对数组赋值
相似回答
大家正在搜