Experiment - 12
Experiment - 12
a. Create a file to hold the data of employees input and output data from it.
b. Write a sentence in a file and convert all lower case alphabets to uppercase and vice
versa
#include <stdio.h>
int main() {
FILE *file;
struct Employee emp;
if (file == NULL) {
printf("Error opening the file.\n");
return -1;
}
if (file == NULL) {
printf("Error opening the file.\n");
return -1;
}
printf("\nEmployee Data:\n");
fscanf(file, "%s %d %f\n", emp.name, &emp.eno, &emp.salary);
printf("Name: %s\n", emp.name);
printf("Employee No: %d\n", emp.eno);
printf("Salary: %.2f\n", emp.salary);
fclose(file);
return 0;
}
12.b. Write a sentence in a file and convert all lower
case alphabets to uppercase and vice versa.
#include <stdio.h>
int main() {
FILE *file1, *file2;
file1 = fopen("file1.txt", "r"); // Open the file1 for reading
file2 = fopen("file2.txt", "w"); // Open the file2 for writing
if (file1 == NULL) {
printf("Error opening the file1.\n");
return -1;
}
char c;