Skip to content

Instantly share code, notes, and snippets.

@webgtx
Created February 25, 2023 00:17
Show Gist options
  • Select an option

  • Save webgtx/0256c289138009278f2309fe75ec680a to your computer and use it in GitHub Desktop.

Select an option

Save webgtx/0256c289138009278f2309fe75ec680a to your computer and use it in GitHub Desktop.
// aHR0cHM6Ly9naXRodWIuY29tL3dlYmd0eAo=
#include <stdbool.h>
#include <stdio.h>
void lnrd(char * str) {
int idx = 0;
while (true) {
char ch = getchar();
if (ch == '\n')
break;
str[idx] = ch;
idx++;
}
str[idx++] = '\0';
}
struct student {
char name[20];
char surname[20];
char whoisfather[20];
int marks[20];
};
struct student new_student() {
struct student new;
int marks[20] = {3, 3, 3, 3};
puts("Write Student Name: ");
lnrd(new.name);
puts("Write Student Surname: ");
lnrd(new.surname);
puts("Who is student father");
lnrd(new.whoisfather);
new.marks[20] = *marks;
return new;
};
int main() {
// Marks encode
// 1 - Bad
// 2 - Not bad
// 3 - Good
struct student students[4] = {
{"Jhon", "Doe", "Jhonson", {2, 1, 3, 2}},
{"Jane", "Doe", "Jhonson", {3, 3, 3, 1}},
{"Bob", "Whitestone", "Willson", {3, 2, 3, 3}}
};
struct student elliot = new_student();
students[4] = elliot;
printf("\n--- [ Best Students ] ---\n");
unsigned len = sizeof students / sizeof *students;
for (unsigned idx = 0; idx < len; idx++) {
unsigned mark_is_good = 0;
for (unsigned counter = 0; counter <= 3; counter++)
if (students[idx].marks[counter] == 3) mark_is_good++;
//if (mark_is_good != 3) continue;
printf("\nName: %s\nSurname: %s\nFather: %s\nMarks: %s\n",
students[idx].name, students[idx].surname, students[idx].whoisfather, mark_is_good == 3 ? "Great" : "Nothing");
printf("[ Marks Stats ] ->\n |- Programming: %i\n |- Math: %i\n |- CPU Loigc: %i\n |- Languages: %i\n",
students[idx].marks[0], students[idx].marks[1], students[idx].marks[2], students[idx].marks[3]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment