在編譯時我有一個錯誤:預期)和(在C以下程序:預期)和(在C錯誤
#include<stdio.h>
#include<conio.h>
struct student
{
char name[20];
int rollno;
int age;
char classes[10];
};
void printdata(struct student &sob); //getting error in this line
void main()
{
struct student stud;
clrscr();
printf("enter student details:");
printf("\nenter student name:"); fflush(stdin);
gets(stud.name);
printf("\nenter age:");
scanf("%d",&stud.age);
printf("\nenter rollno:");
scanf("%d",&stud.rollno);
printf("\nenter class of student:"); fflush(stdin);
gets(stud.claases);
printdata(&stud);
getch();
}
void printdata(struct student &sob) //getting error in this line
{
struct student *ptr;
ptr=sob;
printf("student details are as follows:");
printf("\nstudent's name:"); fflush(stdout);
puts(ptr->name);
printf("\n student' age:%d",ptr->age);
printf("\n student's roll no:%d",ptr->rollno);
printf("\n student's class:"); fflush(stdout);
puts(ptr->classes);
}
這是我已經宣佈了結構的學生那麼爲什麼它給我的錯誤(和)在兩行..
這不是C,看起來更像C++,C中沒有引用。另外,檢查你的拼寫和其他錯誤,編譯器應該告訴你這些。 – Nobilis
使用printf和scanf然後它怎麼可能是C++ ..所以抱歉我的拼寫錯誤,但我得到這兩個錯誤,沒有警告..! – gazer
你使用什麼樣的編譯器?我在'&'令牌之前說'錯誤:預期';',','或')',這使得它更清楚錯誤實際上是什麼。 –