Skip to content

Commit bfa0534

Browse files
Ravi kumarRavi kumar
Ravi kumar
authored and
Ravi kumar
committed
after1st sp internal
1 parent 3808836 commit bfa0534

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1257
-1
lines changed

Login/a.out

13.1 KB
Binary file not shown.

Login/vault.txt

80 Bytes
Binary file not shown.

Ravi Kumar/a.out

13.1 KB
Binary file not shown.

Ravi Kumar/calendarOwn.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,34 @@ void addNote(void)
171171
printf("Note successfully added!\n\n");
172172
}
173173

174+
void deleteNote()
175+
{
176+
int day, month, year;
177+
printf("Entet date in DD MM YYYY format: ");
178+
scanf("%d %d %d", &day, &month, &year);
179+
180+
FILE *fp = fopen("notes.txt", "rb");
181+
struct todo search;
182+
183+
while(fread(&search, sizeof(struct todo), 1, fp) != 0)
184+
{
185+
FILE *new = fopen("notes.txt", "wb");
186+
187+
188+
if( month == search.month && year == search.year && day == search.day )
189+
{
190+
// Do Nothing
191+
}
192+
193+
else
194+
{
195+
fwrite(&search, sizeof(search), 1, new);
196+
}
197+
}
198+
fclose(fp);
199+
200+
}
201+
174202

175203

176204
int main(void) {
@@ -200,7 +228,7 @@ initPattern('-');
200228
leapYear = checkLeapYear(year);
201229
firstDayOfMonth = determineFirstDay(year, month);
202230
printCalendar(firstDayOfMonth, month, year, leapYear);
203-
printf("'n': Go to next month, 'p': Go to previous month, 'a': Add Note, 'q': quit \n");
231+
printf("'n': Go to next month, 'p': Go to previous month, 'a': Add Note, 'd': delete note 'q': quit \n");
204232
scanf(" %c", &choice);
205233
switch(choice) {
206234
case 'n': month = month + 1;
@@ -222,6 +250,10 @@ initPattern('-');
222250
case 'a': addNote();
223251
goto navigate;
224252
break;
253+
254+
case 'd': deleteNote();
255+
goto navigate;
256+
break;
225257

226258
case 'q': return 0;
227259

Ravi Kumar/mainprogram

35 Bytes
Binary file not shown.
File renamed without changes.

Ravi Kumar/test.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
#include<unistd.h>
4+
#include<stdlib.h>
5+
6+
int main()
7+
{
8+
printf("Enter password: ");
9+
char password[10];
10+
int i = 0;
11+
const char *mypass = "ravi";
12+
*password = getpass(" ");
13+
14+
if(!strcmp(password, mypass))
15+
printf("Correct");
16+
else
17+
printf("Not correct");
18+
19+
return 0;
20+
}

Ravi Kumar/vault.txt

400 Bytes
Binary file not shown.

SP Programs/a.out

8.68 KB
Binary file not shown.

SP Programs/at

8.57 KB
Binary file not shown.

SP Programs/atexit.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
4+
static void my_exit1(void);
5+
static void my_exit2(void);
6+
7+
int main(void)
8+
{
9+
if (atexit(my_exit2) != 0)
10+
printf("can't register my_exit2");
11+
12+
if (atexit(my_exit1) != 0)
13+
printf("can't register my_exit1");
14+
15+
if (atexit(my_exit1) != 0)
16+
printf("can't register my_exit1");
17+
18+
printf("main is done\n");
19+
exit(0);
20+
}
21+
22+
static void my_exit1(void)
23+
{
24+
printf("first exit handler\n");
25+
}
26+
27+
static void my_exit2(void)
28+
{
29+
printf("second exit handler\n");
30+
}

SP Programs/avoidzombie.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <sys/wait.h>
2+
#include<stdio.h>
3+
#include<unistd.h>
4+
#include<stdlib.h>
5+
#include<sys/stat.h>
6+
7+
8+
int main(void)
9+
{
10+
pid_t pid;
11+
12+
if ((pid = fork()) < 0)
13+
{
14+
printf("could not fork");
15+
}
16+
else if (pid == 0)
17+
{
18+
/* first child */
19+
if ((pid = fork()) < 0)
20+
printf("could not fork error");
21+
else if (pid > 0)
22+
exit(0);
23+
/* parent from second fork == first child */
24+
/* * We're the second child; our parent becomes init as soon * as our real parent calls exit() in the statement above. * Here's where we'd continue executing, knowing that when * we're done, init will reap our status. */
25+
sleep(2);
26+
printf("second child, parent pid = %d\n", getppid());
27+
exit(0);
28+
}
29+
if (waitpid(pid, NULL, 0) != pid)
30+
/* wait for first child */
31+
printf("waiting failed error");
32+
33+
34+
exit(0);
35+
}

SP Programs/commandline.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
4+
5+
int main(int argc, char *argv[])
6+
{
7+
int i;
8+
char **ptr;
9+
extern char **environ;
10+
11+
for (i = 1; i < argc; i++) /* echo all command-line args */
12+
printf("argv[%d]: %s\n", i, argv[i]);
13+
14+
for (ptr = environ; *ptr != 0; ptr++) /* and all env strings */
15+
printf("%s\n", *ptr);
16+
17+
exit(0);
18+
}

SP Programs/copyio.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
4+
#define BUFFSIZE 4096
5+
6+
7+
int main(void) {
8+
int n;
9+
char buf[BUFFSIZE];
10+
11+
while ((n = read(1, buf, BUFFSIZE)) > 0)
12+
if (write(1 , buf, n) != n)
13+
printf(" could not write");
14+
15+
if (n < 0)
16+
printf("could not read ");
17+
18+
exit(0);
19+
}

SP Programs/filetype.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
4+
#include<unistd.h>
5+
#include<sys/stat.h>
6+
7+
int main(int argc, char *argv[])
8+
{
9+
int i;
10+
struct stat buf;
11+
char *ptr;
12+
13+
for (i = 1; i < argc; i++)
14+
{
15+
printf("%s: ", argv[i]);
16+
if (lstat(argv[i], &buf) < 0)
17+
{
18+
return -1;
19+
continue;
20+
}
21+
if (S_ISREG(buf.st_mode))
22+
ptr = "regular";
23+
else if (S_ISDIR(buf.st_mode))
24+
ptr = "directory";
25+
else if (S_ISCHR(buf.st_mode))
26+
ptr = "character special";
27+
else if (S_ISBLK(buf.st_mode))
28+
ptr = "block special";
29+
else if (S_ISFIFO(buf.st_mode))
30+
ptr = "fifo";
31+
else if (S_ISLNK(buf.st_mode))
32+
ptr = "symbolic link";
33+
else if (S_ISSOCK(buf.st_mode))
34+
ptr = "socket";
35+
else
36+
ptr = "** unknown mode **";
37+
printf("%s\n", ptr);
38+
}
39+
exit(0);
40+
}
41+

SP Programs/fork.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include<stdio.h>
2+
#include<unistd.h>
3+
#include<stdlib.h>
4+
5+
int glob = 6;
6+
7+
int main(void)
8+
{
9+
int var;
10+
int var1=5;
11+
12+
pid_t pid;
13+
14+
var = 88;
15+
printf("before fork\n");
16+
17+
if ((pid = fork()) < 0)
18+
{
19+
printf(" not able to fork child");
20+
}
21+
else if (pid == 0)
22+
{
23+
glob++;
24+
var++;
25+
_exit(0);
26+
}
27+
else if(pid > 0)
28+
{
29+
wait(&var1);
30+
printf("Inside parent \n");
31+
32+
}
33+
printf("pid = %d, glob = %d, var = %d\n", getpid(), glob, var);
34+
exit(0);
35+
}

SP Programs/jumpfrombook.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include<setjmp.h>
2+
#include<stdio.h>
3+
#include<stdlib.h>
4+
5+
void f1(int, int, int, int);
6+
void f2(void);
7+
8+
jmp_buf jmpbuffer;
9+
static int globval;
10+
11+
int main(void) {
12+
int autoval;
13+
register int regival;
14+
volatile int volaval;
15+
static int statval;
16+
17+
globval = 1;
18+
autoval = 2;
19+
regival = 3;
20+
volaval = 4;
21+
statval = 5;
22+
23+
if (setjmp(jmpbuffer) != 0)
24+
{
25+
printf("after longjmp:\n");
26+
printf("globval = %d, autoval = %d, regival = %d," " volaval = %d, statval = %d\n", globval, autoval, regival, volaval, statval);
27+
exit(0);
28+
}
29+
30+
31+
globval = 95; autoval = 96; regival = 97; volaval = 98; statval = 99;
32+
f1(autoval, regival, volaval, statval);
33+
34+
exit(0); }
35+
36+
void f1(int i, int j, int k, int l)
37+
{
38+
printf("in f1():\n");
39+
printf("globval = %d, autoval = %d, regival = %d," " volaval = %d, statval = %d\n", globval, i, j, k, l);
40+
f2();
41+
}
42+
void f2(void)
43+
{
44+
longjmp(jmpbuffer, 1);
45+
}

SP Programs/ls_command.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "apue.h"
2+
#include <dirent.h>
3+
int main(int argc, char *argv[])
4+
{
5+
DIR *dp;
6+
struct dirent *dirp;
7+
if (argc != 2)
8+
err_quit("usage: ls directory_name");
9+
if ((dp = opendir(argv[1])) == NULL)
10+
err_sys("can’t open %s", argv[1]);
11+
while ((dirp = readdir(dp)) != NULL)
12+
printf("%s\n", dirp->d_name);
13+
closedir(dp);
14+
exit(0);
15+
16+
}

SP Programs/move.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include<stdio.h>
2+
#include<fcntl.h>
3+
4+
int main(int argc, char *argv[])
5+
{
6+
if(argc != 3)
7+
{
8+
printf("Provide only 2 arguments\n");
9+
return 1;
10+
}
11+
link(argv[1], argv[2]);
12+
unlink(argv[1]);
13+
return 0;
14+
}

SP Programs/pipe.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include<stdio.h>
2+
#include<unistd.h>
3+
#include<stdlib.h>
4+
#define MAXLINE 100
5+
6+
7+
8+
int main(void)
9+
{
10+
int n;
11+
int fd[2];
12+
pid_t pid;
13+
char line[MAXLINE];
14+
15+
if (pipe(fd) < 0)
16+
printf("pipe error");
17+
if ((pid = fork()) < 0)
18+
{
19+
printf("fork error");
20+
}
21+
else if (pid > 0)
22+
{ /* parent */
23+
close(fd[0]);
24+
write(fd[1], "hello world\n", 12);
25+
}
26+
else
27+
{
28+
/* child */
29+
close(fd[1]);
30+
n = read(fd[0], line, MAXLINE);
31+
write(STDOUT_FILENO, line, n);
32+
}
33+
exit(0);
34+
}

0 commit comments

Comments
 (0)