Professional Documents
Culture Documents
Aditya
Aditya
OUTPUT: -
OUTPUT: -
CODE: -
#include <stdio.h>
#include<conio.h>
int main() {
FILE *inputFile, *oddFile, *evenFile;
int number;
clrscr();
inputFile = fopen("data.txt", "r");
if (inputFile == NULL) {
printf("Error opening the input file.\n");
return 1;
}
oddFile = fopen("odd.txt", "w");
evenFile = fopen("even.txt", "w");
if (oddFile == NULL || evenFile == NULL) {
printf("Error opening the output files.\n");
fclose(inputFile);
return 1;
}
while (fscanf(inputFile, "%d", &number) == 1) {
if (number % 2 == 0) {
fprintf(evenFile, "%d\n", number);
} else {
OUTPUT: -
CODE: -
#include <stdio.h>
#include<conio.h>
int main() {
FILE *filePointer;
char fileName[50];
int n;
printf("Enter the filename: ");
scanf("%s", fileName);
filePointer = fopen(fileName, "w");
if (filePointer == NULL) {
printf("Error opening the file.\n");
return 1; // Return with an error code
}
printf("Enter the number of students: ");
scanf("%d", &n);
for (int i = 0; i < n; i++) {
char name[50];
int marks;
printf("Enter the name of student %d: ", i + 1);
scanf("%s", name);
printf("Enter the marks of student %d: ", i + 1);
scanf("%d", &marks);
fprintf(filePointer, "%s %d\n", name, marks);
}
fclose(filePointer);
>OUTPUT: -
return 1;
}
int main() {
FILE *file1, *file2;
char fileName1[50], fileName2[50];
printf("Enter the first filename: ");
OUTPUT: -
File1.txt
File2.txt
CODE: -
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
void copyBytes(FILE *source, FILE *destination, long offset, size_t numBytes) {
fseek(source, offset, SEEK_SET);
char *buffer = (char *)malloc(numBytes);
if (buffer == NULL) {
printf("Memory allocation failed.\n");
exit(1); // Exit with an error code
}
size_t bytesRead = fread(buffer, 1, numBytes, source);
fwrite(buffer, 1, bytesRead, destination);
free(buffer);
}
int main() {
FILE *sourceFile, *destinationFile;
char sourceFileName[50], destinationFileName[50];
long offset;
size_t numBytes;
clrscr();
printf("Enter the source filename: ");
scanf("%s", sourceFileName);
sourceFile = fopen(sourceFileName, "rb");
if (sourceFile == NULL) {
OUTPUT: -
OUTPUT: -