// Read alternate values from a file c programming.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,a,v;
clrscr();
FILE *p;
printf("enter the limit: ");
scanf("%d",&n);
p=fopen("values","wb");
printf("enter the numbers: \n");
for(i=0;i<n;i++)
{
scanf("%d",&a);
putw(a,p);
}
fclose(p);
p=fopen("values","rb");
printf("Alternative numbers are: \n");
a=getw(p);
while(!feof(p))
{
printf("%d\t",a);
fseek(p,2,1);
a=getw(p);
}
fclose(p);
getch();
}
Output
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,a,v;
clrscr();
FILE *p;
printf("enter the limit: ");
scanf("%d",&n);
p=fopen("values","wb");
printf("enter the numbers: \n");
for(i=0;i<n;i++)
{
scanf("%d",&a);
putw(a,p);
}
fclose(p);
p=fopen("values","rb");
printf("Alternative numbers are: \n");
a=getw(p);
while(!feof(p))
{
printf("%d\t",a);
fseek(p,2,1);
a=getw(p);
}
fclose(p);
getch();
}
Output
C program to read alternate values from a file |
No comments:
Post a Comment