注册 登录
编程论坛 C语言论坛

莫名其妙的错误

lbjmvp 发布于 2020-05-04 19:27, 1774 次点击
#include<stdio.h>
#include<string.h>
main()
typedef struct
{char name[10];  \就是这行,奇怪了
int p;}stu;
{char a[10];
stu person[3]={{"白",0},{"李",0},{"木",0}};
int i,j;
for(i=0;i<10;i++)
{scanf("%3s",&a[i]);}
for(j=0;j<3;j++)
{if(stu person[j].name==a[i])
{stu person[j].p++;}}
for(j=0;j<3;j++)
printf("%s:%d\n",stu person[j].p);
return 0;}





C:\Users\Administrator\Desktop\type.cpp(5) : error C2143: syntax error : missing ';' before '<class-head>'
C:\Users\Administrator\Desktop\type.cpp(5) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.

type.obj - 1 error(s), 0 warning(s)
2 回复
#2
yiyue1232020-05-04 21:36
为啥要把 typedef 插在 main 函数的函数头与函数体之间?
#3
yiyue1232020-05-04 21:41
程序代码:
#include<stdio.h>
#include<string.h>
typedef struct
{
    char name[10];
    int p;
} stu;
int main()
{
    char a[10];
    stu person[3]={{"w",0},{"l",0},{"m",0}};
    int i,j;
    for(i=0;i<10;i++)
    {
        scanf("%3s",&a[i]);
    }
    for(j=0;j<3;j++)
    {
        if(person[j].name==a[i])
        {
            person[j].p++;
        }
    }
    for(j=0;j<3;j++)
    printf("%s:%d\n", person[j].p);
    return 0;
}

嘛,这么一改,程序是没问题了,但是比较指针与字符,以及程序要表达什么意思我还真不清楚。
1