-
Notifications
You must be signed in to change notification settings - Fork 0
/
ManagerAvi.c
87 lines (70 loc) · 2.15 KB
/
ManagerAvi.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
#include <stdio.h>
#include <unistd.h>// for fork
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>
/**********Structure**********/
struct User{
char employeeName[50];
char jobTitle[50];
char status[50];
};
/**********UserInput**********/
int structure(){
struct User *userPtr, user;
userPtr = &user;
int fd;
// file path
char * myfifo = "myfifo.txt";
// Creating the file
mkfifo(myfifo, 0644);
char arr, arr1, arr2;
char ch, temp;
// Open file fo write only
fd = open(myfifo, O_WRONLY);
printf("click enter to continue\n");
while(1){
scanf("%c",&temp); // temp statement to clear buffer
// Take user UserInput and write to file
printf("Enter Employee Name: ");
scanf("%[^\n]", userPtr->employeeName);
printf("Enter Job Title: ");
scanf("%c",&temp); // temp statement to clear buffer
scanf("%[^\n]", userPtr->jobTitle);
printf("Enter Status: ");
scanf("%c",&temp); // temp statement to clear buffer
scanf("%[^\n]", userPtr->status);
char *space = ",";
char *arr = userPtr->employeeName;
char *arr1 = userPtr->jobTitle;
char *arr2 = userPtr->status;
unsigned int const sz1 = strlen(arr);
unsigned int const sz2 = strlen(arr1);
unsigned int const sz3 = strlen(arr2);
unsigned int const szSpace = strlen(space);
char *concat = (char*)malloc(sz1+sz2+sz3+3);
memcpy( concat, arr , sz1 );
memcpy( concat+sz1, space , szSpace);
memcpy( concat+sz1+szSpace, arr1 , sz2 );
memcpy( concat+sz1+szSpace+sz2, space , szSpace);
memcpy( concat+sz1+szSpace+sz2+szSpace, arr2 , sz3 );
memcpy( concat+sz1+szSpace+sz2+szSpace+sz3, space , szSpace);
concat[sz1+ szSpace + sz2 + szSpace + sz3 +szSpace] = '\0';
write(fd, concat, strlen(concat));
//printf("%s\n", concat);
printf("Do you want to continue? y/n: ");
scanf("%s", &ch);
if(ch == 'y'){
continue;
}
// End program if user input is 'n'
else if(ch == 'n'){
close(fd);
return 0;
}
}
return 0;
}