C Programs using File Operations - THE getw AND putw FUNCTIONS
/*Example C program for using getw and putw functions*/
#include <stdio.h>
#include <conio.h>
main()
{
FILE *fl, *f2, *f3;
int n, i;
clrscr();
printf("Contents of the data file\n\n");
fl=fopen("DATA", "w");
for(i=1;i < = 10;i++)
{
scanf("%d", &n);
if(n ==‒1) break;
putw (n,fl);
}
fclose(fl);
fl=fopen("DATA", "r");
f2=fopen("ODD", "w");
f3=fopen("EVEN", "w");
while((n=getw (f1))!= EOF) * Read from data file*!
{
if(n%2==0) putw(n,f3); /*Write to even file*/
else putw (n,f2); /*write to odd File*/
}
fclose(fl);
fclose(f2);
fclose(f3);
f2=fopen("ODD", "r");
f3=fopen("EVEN", "r");
printf("\n\n Contents of the odd file\n\n");
while((n=getw (f2))!= EOF) printf("%d\t",n);
printf("\n\nContents of the even file\n");
while((n=getw (f3))!= EOF) printf("%d\t",n);
fclose(f2);
fclose(f3);
}
OUTPUT
Contents of the data file
1 2 3 4 5 6 7 8 9 10
Contents of the odd file
1 3 5 7 9
Contents of the even file
2 4 6 8 10
Computer Programming C Laboratory: File Operations C Programs : Tag: C Programming : - Example C program for using getw and putw functions
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
English Essentials I
EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
தமிழர் மரபு - Heritage of Tamils
UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Calculus
MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I
PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Applied Chemistry I
CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Makerspace
ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming C
CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Computer Programming Python
CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation
Fundamentals of Electrical and Electronics Engineering
EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Mechanical Engineering
ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation
Introduction to Civil Engineering
CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing
CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation
Applied Physics I Laboratory
PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Applied Chemistry I Laboratory
CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming C Laboratory
CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Computer Programming Python Laboratory
CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation
Engineering Drawing
ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation
Basic Electronics and Electrical Engineering
EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation
Essentials of Computing - Laboratory
CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation