26 lines
476 B
C
26 lines
476 B
C
#include "student.h"
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
|
|
struct Student {
|
|
char name[50];
|
|
int age;
|
|
};
|
|
|
|
struct Student* new_student(char* name, int age) {
|
|
struct Student* t = (struct Student*) malloc(sizeof(struct Student));
|
|
|
|
if(t == NULL) return NULL;
|
|
|
|
strncpy(t->name, name, 49);
|
|
t->name[49] = '\0';
|
|
t->age = age;
|
|
|
|
return t;
|
|
}
|
|
|
|
void change_name(struct Student* s, char* name){
|
|
strncpy(s->name, name, 49);
|
|
s->name[49] = '\0';
|
|
}
|