Declare type of data structure

2
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

struct estudiante {
    int ced;
    int aniocarrera;
    char grupo;
};
estudiante e; //<-error: unknown type name 'estudiante'
int I;
void ingresar(estudiante* e) {
    printf(" Ingresar la cedula ");
    scanf("%d",&e.ced);
    printf("Ingresar el año de la carrera ");
    scanf("%d",&e.aniocarrera);
    printf("Ingrese el grupo ");
    scanf("%c",&e.grupo);
}

void mostrar(estudiante alum) {
    printf("La cedula es ");
    printf("%d", e.ced);
    printf("\r\n");
    printf("El año de la carrera es ");
    printf("%d", e.aniocarrera);
    printf("\r\n");
    printf("El grupo es ");
    printf("%c", e.grupo);
    printf("\r\n");
}

int main() {
    ingresar(e);
    mostrar(e);
    getch();
    return 0;
}

Shoot the following errors:

  

error: unknown type name 'student'

    
asked by Alejandro Caro 01.09.2017 в 22:47
source

2 answers

1

The correction was partially fine, you corrected access to the elements of the structure, but the data type structure was still undefined. You have to define the type of data structure, which is what PS: Clean the buffer in after the second scanf

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

struct estudiante {
    int ced;
    int aniocarrera;
    char grupo;
};
typedef struct estudiante estudiante;
estudiante e;
void ingresar(estudiante* e) {
    printf("Ingresar la cedula: ");
    scanf("%d",&e->ced);
    printf("Ingresar el a%co de la carrera: ",164);
    scanf("%d",&e->aniocarrera);
    fflush(stdin);
    printf("Ingrese el grupo: ");
    scanf("%c",&e->grupo);
}

void mostrar(estudiante e) {
    printf("\n\nLa cedula es: %d",e.ced);
    printf("\nEl a%co de la carrera es: %d",164,e.aniocarrera);
    printf("\nEl grupo es: %c",e.grupo);
}

int main() {
    ingresar(&e);
    mostrar(e); 
    getch();
    return 0;
}
    
answered by 02.09.2017 / 23:43
source
2

The correction of your code would be like this:

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

struct estudiante {
    int ced;
    int aniocarrera;
    char grupo;
}e;

void ingresar(struct estudiante* e) {
    printf("Ingresar la cedula: ");
    scanf("%d",&e->ced);
    printf("Ingresar el a%co de la carrera: ",164);
    scanf("%d",&e->aniocarrera);
    printf("Ingrese el grupo: ");
    scanf("%s",&e->grupo);
}

void mostrar(struct estudiante e) {
    printf("\n\nLa cedula es: %d",e.ced);
    printf("\nEl a%co de la carrera es: %d",164,e.aniocarrera);
    printf("\nEl grupo es: %c",e.grupo);
}

int main() {
    ingresar(&e);
    mostrar(e); 
    getch();
    return 0;
}

As I told you in the comment above if you use a variable type char you can not use% d.

The function void enter (student * e) is passing it a pointer, so in the data assignment you must use the arrow - > and not the point.

    
answered by 02.09.2017 в 00:41