-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtotxtfile.h
74 lines (59 loc) · 2.26 KB
/
totxtfile.h
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct
{
char phone[10];
char name[20];
char address[50];
char email[30];
}contact_file;
void add2file(contact_file students[],int TOTAL_STUDENTS)
{
FILE *fptr;
fptr=fopen("./output.txt","w");
fprintf(fptr,"LIST OF ALL CONTACTS\n");
fprintf(fptr,"-----------------------------------------------------------------------------------------------------------------\n");
fprintf(fptr,"| PHONE ");
fprintf(fptr,"| NAME ");
fprintf(fptr,"| ADDRESS ");
fprintf(fptr,"| EMAIL |\n");
fprintf(fptr,"-----------------------------------------------------------------------------------------------------------------\n");
for(int i=0;i<TOTAL_STUDENTS;i++)
{
fprintf(fptr,"|");
fprintf(fptr," %s",students[i].phone);
int phonelength=10-strlen(students[i].phone);
for(int k=0;k<phonelength;k++){
fprintf(fptr," ");
}
fprintf(fptr,"|");
fprintf(fptr," %s",students[i].name);
int namelength=18-strlen(students[i].name);
for(int k=0;k<namelength;k++){
fprintf(fptr," ");
}
fprintf(fptr,"|");
fprintf(fptr," %s",students[i].address);
int addresslength=48-strlen(students[i].address);
for(int k=0;k<addresslength;k++){
fprintf(fptr," ");
}
fprintf(fptr,"|");
fprintf(fptr," %s",students[i].email);
int emaillength=28-strlen(students[i].email);
for(int k=0;k<emaillength;k++){
fprintf(fptr," ");
}
fprintf(fptr,"|\n");
}
fprintf(fptr,"-----------------------------------------------------------------------------------------------------------------\n");
fclose(fptr);
printf("-----------------------------------------------------------------------------------------------------------------\n");
printf("OPERATION SUCCESSFUL\n");
printf("-----------------------------------------------------------------------------------------------------------------\n");
printf("PRESS ANY KEY TO RETURN TO THE MAIN MENU\n");
char s[4];
scanf("%s",s);
system("clear");
}