Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7ca6482

Browse files
Add files via upload
1 parent 9556553 commit 7ca6482

File tree

3 files changed

+137
-0
lines changed

3 files changed

+137
-0
lines changed

β€ŽPROGRAMS/10. Files/Exp10_1.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
typedef struct book
4+
{
5+
char type;
6+
char name[50];
7+
char author[20];
8+
} book_t;
9+
int print(char filename[])
10+
{
11+
FILE *fp, *fp1, *fp2;
12+
fp = fopen(filename, "r");
13+
if (fp == NULL)
14+
{
15+
printf("File Not Found");
16+
return 0;
17+
}
18+
book_t b;
19+
fp1 = fopen("Paperbacks.txt", "w");
20+
fp2 = fopen("Hardbacks.txt", "w");
21+
while (fscanf(fp, " %c, %[^,],%[^\n]\n", &b.type, b.name, b.author) != EOF)
22+
{
23+
if (b.type == 'b')
24+
{
25+
fprintf(fp1, "%s, %s\n", b.name, b.author);
26+
fprintf(fp2, "%s, %s\n", b.name, b.author);
27+
}
28+
else if (b.type == 'p')
29+
fprintf(fp1, "%s, %s\n", b.name, b.author);
30+
else if (b.type == 'h')
31+
fprintf(fp2, "%s, %s\n", b.name, b.author);
32+
}
33+
fclose(fp1);
34+
fclose(fp2);
35+
fclose(fp);
36+
return 0;
37+
}
38+
int main()
39+
{
40+
int i;
41+
char filename[20];
42+
printf("Enter the name of the file where the records are kept: ");
43+
scanf("%s", filename);
44+
strcat(filename, ".txt");
45+
i = print(filename);
46+
return 0;
47+
}

β€ŽPROGRAMS/10. Files/Exp10_2.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
typedef struct vehicle
4+
{
5+
char reg[7];
6+
char name[30];
7+
char addr[30];
8+
} vehicle_t;
9+
int print(char filename[])
10+
{
11+
FILE *fp;
12+
fp = fopen(filename, "r");
13+
if (fp == NULL)
14+
{
15+
printf("FILE NOT FOUND!\n");
16+
return 0;
17+
}
18+
fclose(fp);
19+
vehicle_t v;
20+
int n, flag = 1;
21+
char rg[7];
22+
printf("Enter the number of records you want to search: ");
23+
scanf("%d", &n);
24+
for (int i = 0; i < n; i++)
25+
{
26+
fp = fopen(filename, "r");
27+
printf("\nEnter the registration number: ");
28+
scanf(" %s", rg);
29+
30+
while (fscanf(fp, "%[^,],%[^,],%[^\n]\n", v.reg, v.name, v.addr) != EOF)
31+
if (strcmp(v.reg, rg) == 0)
32+
{
33+
printf("%s %s %s\n", v.reg, v.name, v.addr);
34+
flag = 0;
35+
break;
36+
}
37+
if (flag)
38+
printf("Not Found\n");
39+
flag = 1;
40+
fclose(fp);
41+
}
42+
return 0;
43+
}
44+
int main()
45+
{
46+
int i;
47+
char filename[20];
48+
printf("Enter the name of the file: ");
49+
scanf(" %s", filename);
50+
strcat(filename, ".txt");
51+
i = print(filename);
52+
return 0;
53+
}

β€ŽPROGRAMS/10. Files/Exp10_3.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
void check(char filename1[], char filename2[])
4+
{
5+
int day1, day2, count = 0;
6+
char events[20];
7+
FILE *fp1, *fp2;
8+
fp1 = fopen(filename1, "r");
9+
fp2 = fopen(filename2, "r");
10+
while (fscanf(fp2, "%d\n", &day1) != EOF)
11+
{
12+
while (fscanf(fp1, "%d, %[^\n]\n", &day2, events) != EOF)
13+
{
14+
if (day2 == day1)
15+
count++;
16+
else
17+
{
18+
printf("%d %d\n", day1, count);
19+
count = 1;
20+
break;
21+
}
22+
}
23+
}
24+
printf("%d %d\n", day1, count);
25+
}
26+
int main()
27+
{
28+
char filename1[20], filename2[20];
29+
printf("Enter the filename containing the events: ");
30+
scanf("%s", filename1);
31+
strcat(filename1, ".txt");
32+
printf("Enter the filename containing the dates: ");
33+
scanf("%s", filename2);
34+
strcat(filename2, ".txt");
35+
check(filename1, filename2);
36+
return 0;
37+
}

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /