-
Notifications
You must be signed in to change notification settings - Fork 0
/
proj1.0.c
93 lines (70 loc) · 1.48 KB
/
proj1.0.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <stdbool.h>
static char name[20];
int nm();
int file();
int write();
int dyww();
int nm(){
printf("Please enter your file name:-");
fgets(name,20,stdin);
return 0;
}
int file(){
FILE *fl;
fl=fopen(name,"w");
printf("empty file created called %s has been created.\n",name);
fclose(fl);
if (fclose==0)
printf("err closing file;%c \n");
return 0;
}
FILE *fli;
int write(){
fli=fopen(name,"a+");
if(fli != NULL)
{
system("clear");
printf("file opened sucessfully please enter text\n");
printf("-----------------------------------------\n");
while(true){
char *text=NULL;
size_t len=0;
ssize_t bytes=getline(&text,&len,stdin);
if (bytes>1){
if(strcmp(text,"exit\n")==0){
break;
}
printf("%i bytes entered\n",(bytes-1));
fprintf(fli,"%s\n",text);
}
}
}
free(fli);
if(!fclose(fli)){
perror("err closing file: \n");
return 1;
}
return 0;
}
int dyww(){
char *o;
printf("Do you want to add anything to your file:-\ny -yes \nn -no \nAns:");
o= fgets(o,2,stdin);
if (strcmp(o,"y") == 0){
write();
}
else{
printf("Okay, Thank you \n");
}
}
int main()
{
nm();
file();
dyww();
return 0;
}