-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.c
43 lines (41 loc) · 916 Bytes
/
array.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "lib/all-structs.h"
#include "lib/array.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "lib/parsing.h"
array input_array()
{
FILE *fptr;
fptr=fopen("database/students.dat", "r");
if (fptr==NULL){
printf("PROBLEM OCCURED WHILE OPENING FILE\n");
exit(0);
}
char str[200];
array all_students;
all_students.students=malloc(sizeof(Student));
all_students.size=1;
while(!feof(fptr))
{
size_t size = 200;
fgets(str, size, fptr);
if(strlen(str)<=1)break;
Student *st=parse_student(str);
push_back(&all_students.students,st,&all_students.size);
uninitialize_Student(st);
fflush(stdout);
memset(str,0,sizeof(str));
}
all_students.size--;
fclose(fptr);
return all_students;
}
void element_delete(Student *students,int *size,int id)
{
for(int i=id;i<(*size)-1;i++)
{
students[i]=students[i+1];
}
(*size)--;
}