Sure, standby - horribly basic, but you get the idea. You define a struct with global scope, (generally a good practice), and then create the array of it, in the main function and send it around to where you want, from there. Of course, any function can then create an instance of that same struct, as needed.
Code:
//basics of using array of structs w/o dynamic memory allocation/pointers
#include <stdio.h>
#include <math.h>
#define studNum 4
struct student {
char name[25];
float mark1;
float mark2;
float gpa;
int c1;
int c2;
int no_stud;
};
float compute(struct student*, int i );
void input_data(struct student*, int num_stud);
void printIt(struct student*);
static void force_fpf() //just forces floating point linkage
{
float x, *y; /* Just declares two variables */
y = &x; /* Forces linkage of FP formats */
x = *y; /* Suppress warning message about x */
}
int main(void) {
int i, num_stud;
struct student stud[studNum];
for(i = 1; i < studNum; ++i)
stud[i].no_stud = i; //stud[0] isn't used
for(i = 1; i < studNum; ++i) {
input_data(stud, i);
}
for(i = 1; i < studNum; ++i)
stud[i].gpa = compute(stud, i);
printIt(stud);
printf("\n\n\t\t\t press enter when ready");
while((i = getchar()) != '\n'); //holds the text window openi
i = getchar();
return 0;
}
void input_data(struct student *stud, int num) {
printf("\n Enter students name [24 letters]: ");
scanf("%s", stud[num].name) ; //strings need no addresses
printf("\n Enter students first mark [0-100]: ");
scanf("%f", &stud[num].mark1);
printf("\n Enter students second mark [0-100]: ");
scanf("%f", &stud[num].mark2);
printf("\n Enter students first course score [0-100]: ");
scanf("%d", &stud[num].c1);
printf("\n Enter students second course score [0-100]: ");
scanf("%d", &stud[num].c2);
printf("\n Enter students ID number [1-32000]: ");
scanf("%d", &stud[num].no_stud);
}
float compute(struct student* stud, int i) {
return ((stud[i].mark1 + stud[i].mark2 + stud[i].c1 + stud[i].c2)/4.00);
}
void printIt(struct student* stud) {
int i;
for(i = 1; i < studNum; ++i) {
printf("\n Name: %s mark1: %.2f mark2: %.2f", stud[i].name, stud[i].mark1, stud[i].mark2);
printf("\n GPA: %.2f C1: %d C2: %d Student No: %d", stud[i].gpa, stud[i].c1, stud[i].c2, stud[i].no_stud);
}
}