c - Changing a structure from inside of a function -
im suppose print pupil details user pupil construction , don't understand why when compile linux terminal, there no entry or output. please hep me, i'm new here.
this code:
#include <stdio.h> #include <stdlib.h> struct pupil { char *name; int id; char enroll; }; int main() { struct pupil john; john.name = "john smith"; john.id = 12345678; john.enroll = 'd'; } void getstudent(struct pupil *john) { printf("type name of student: "); john->name = malloc(100); fgets(john->name, 100, stdin); printf("\ntype pupil number: "); scanf("%d", &(john->id)); printf("\ntype pupil enrollment alternative (d or x): "); scanf("%c", &(john->enroll)); return; } void printstudent(struct pupil john) { printf("student name: %s\n", john.name); printf("student number: %d\n", john.id); printf("student enrollment option: %c\n", john.enroll); return; }
you need phone call functions main (or function needs them). writing function (declaring it) doesn't execute it.
int main() { foo(); // execute foo (call it) } void foo() { // stuff }
your functions functions printf() , scanf() , have called used.
c struct
No comments:
Post a Comment