Add struct and its tests

This commit is contained in:
Sambo Chea 2020-07-31 21:25:15 +07:00
parent 5c845a0ee1
commit 7f4670089c
3 changed files with 45 additions and 0 deletions

4
tests/run Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
gcc work1.c -o work1
./work1

BIN
tests/work1 Executable file

Binary file not shown.

41
tests/work1.c Normal file
View File

@ -0,0 +1,41 @@
#include "stdio.h"
#include "string.h"
struct person_tag
{
char name[20];
char id[10];
};
struct course_tag
{
char course_name[20];
int no_of_units;
int marks[4];
float avg;
};
struct student_tag
{
struct person_tag student_info;
struct course_tag course_info;
struct student_tag *next;
};
int main()
{
struct person_tag person, person2 = {"Chea", "4567892"}, *personPtr;
// strcpy style
strcpy(person.id, "2345678");
strcpy(person.name, "Sambo");
personPtr = &person;
printf("Hello, %s \n", person.name);
printf("Hello, %s \n", person2.name);
printf("Hello Ptr, %s \n", personPtr->name);
return 0;
}