C Program to print student details using structure


In this program, You will learn how to print student details using structure in C.


struct struct_name { };


Example: How to print student details using structure in C

Run it Now
#include<stdio.h>
#include<string.h>

struct Student {
    int roll;
    char name[100];
    char university[100];
};

int main() {

    struct Student st;

    printf("Enter Your Roll : ");
    scanf("%d\n", &st.roll);

    printf("\nEnter Your Name : ");
    fgets(st.name, 100, stdin);
    strtok(st.name, "\n");

    printf("\nEnter University Name : ");
    fgets(st.university, 100, stdin);

    printf( "\n\nYour Roll is : %d", st.roll);
    printf( "\nYour Name is : %s", st.name);
    printf( "\nYour University is : %s", st.university);

    return 0;
}

Output:

Enter Your Roll : 101
Enter Your Name : John
Enter University Name : Texas

Your Roll is : 101
Your Name is : John
Your University is : Texas