为什么示值误差&QUOT编译器;螺栓之前的预期前pression"? [英] Why is the compiler showing error "expected expression before stud"?

查看:246
本文介绍了为什么示值误差&QUOT编译器;螺栓之前的预期前pression"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此计划预计将做几件事情:
1.添加使用ID新生
2.搜索按学生ID
3.搜索学生的名字
4.列出所有的学生
谁取得80马克学生5.显示列表及以​​上

This program is expected to do a few things: 1. Add new student using ID 2. Search for student by ID 3. Search for student by name 4. List all the students 5. Display list of students who achieved 80 marks and above

这是我迄今所做

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 200
int i;
int id;

/*Declaration of structures*/
typedef struct student{
    char studID[20];
    char name[50];
    char address[80];
    char tel_no[15];
    float marks; 
} stud;

int add_Name ();
int menu_Display ();
int get_Menu ();
int get_Option ();
int stud_id();
int stud_Name();

int main() {
    menu_Display ();
    get_Menu ();
    get_Option ();
    getchar();

    return 0;
}

int menu_Display () {
    int choice=0;
    while (choice!=6) {
        get_Menu ();
        choice = get_Option();
    }
}

int get_Menu (){
    int i;
    for (i=0; i<1; i++) {
        printf ("\t1. Insert new student\n\n");
        printf ("\t2. Search for a particular student by ID\n\n");
        printf ("\t3. Search for a particular student by name\n\n");
        printf ("\t4. Display a list of all students \n\n");
        printf ("\t5. Display a list of students achieving 80.0 marks and above\n\n");
        printf ("\t6. Exit\n\n");
    }
}

int get_Option () {
    int option;
    printf ("Please enter your option...");
    scanf ("%d", &option);
}

int menu_Option (int option) {
    int i;
    switch (option) {
        case 1 : add_ID();
        break;
        case 2 : stud_id();
        break;
        case 3 : stud_Name();
        break;
        case 4 : list_students();
        break;
        case 5 : students_marks();
        break;
        case 6 : printf("Exit\n");
        break;
        default : printf ("Wrong input");
        i=getchar();
        break;
    }
}

int add_ID () {
    int i;
    struct student stud[200];
    for (i=0; i<1; i++){
        strcpy(stud[i].studID,"ID00");

        printf("Enter Name:\n");
        scanf("%s", &(stud[i].name)) ;

        printf("Enter address:\n");
        scanf("%s", &(stud[i].address));

        printf("Enter telephone number:\n");
        scanf("%s", &(stud[i].tel_no));

        printf("Enter marks:\n"); 
        scanf("%f", &(stud[i].marks));
    }      
}

int stud_Name() {
    int i;
    int result;
    char name[20];

    printf("Please enter the name of the student\n");
    gets(name);

    for (i = 0; i < MAX; i++) {
        if ((result = strcmp(stud[i].name, name)) == 0){
            printf("%s \t %s \t %s \t %s \t %.2f \n", stud[i].studID, stud[i].name, stud[i].address, stud[i].tel_no, stud[i].marks);
        }

    if (i == MAX) {
        printf ("Match not found\n");
    }

    i=getchar();
    }
}

int stud_id() {
    int i;
    int result;
    char ID[20];

    printf("Please enter the Student ID which you are searching for\n");
    gets(ID);

    for (i = 0; i < MAX; i++) {
        if ((result = strcmp(stud[i].studID, ID)) == 0){
            printf("%s \t %s \t %s \t %s \t %.2f \n", stud[i].studID, stud[i].name, stud[i].address, stud[i].tel_no, stud[i].marks);
        }

    if (i == MAX) {
        printf ("Match not found\n");
    }

    i=getchar();
    }
}

int list_Students(){
    printf("Student ID \t Name \t Address \t Telephone number \t Marks \n");

    for (i = 0; i < MAX; i++) {
        printf("%s \t %s \t %s \t %s \t %.2f \n", stud[i].studID, stud[i].name, stud[i].address, stud[i].tel_no, stud[i].marks);

    }   
}

而试图编译程序我也遇到了一些错误。
所示的错误是功能 stud_Name stud_id 和'钉'之前的预期前pression list_Students 。我试图修改code,但没有任何工程。我使用 STRCMP 的正确方法?谢谢

I have encountered a few errors while trying to compile the program. The error shown was "Expected expression before 'stud'" in functions stud_Name, stud_id and list_Students. I have tried to modify the code but nothing works. Am I using strcmp the right way? Thanks

推荐答案

您已经使用的typedef 来命名您的结构以螺柱的typedef 不会创建变量,它可以让你创建一个不字变量结构

You have used typedef to name your struct to stud. typedef does not create variable, it allows you to create variable without word struct.

例如:

typedef struct NameOfStruct { } ShortName;
struct NameOfStruct var1; // Creates variable named var1 
ShortName var2; // Creates variable named var2

看来你要使用螺柱作为一个全局变量。在这种情况下,你应该删除行结构学生螺栓[200]; add_ID()

It seems you want to use stud as a global variable. In such case, you should remove line struct student stud[200]; from add_ID().

您可以创建全局变量螺柱这样的(注意,这不使用Word 的typedef

You can create global variable stud like this (note that this does not use word typedef):

struct student{
    char studID[20];
    char name[50];
    char address[80];
    char tel_no[15];
    float marks; 
} stud[200];

这篇关于为什么示值误差&QUOT编译器;螺栓之前的预期前pression&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆