Write a ‘C’ program to accept the data from user, store it into text file
#include<stdio.h>
void main()
{
FILE *fp1;
char *fname,ch[20];
clrscr();
printf("\n enter source file name\t");
gets(fname);
fp1=fopen(fname,"w");
if(fp1==NULL)
{
printf("\n unable to open\n");
exit(0);
}
printf("\n enter the data:");
scanf("%s",ch);
fprintf(fp1,"%s",ch);
fflush(stdin);
printf("\n data store in %s",fname);
fclose(fp1);
getch();
}
void main()
{
FILE *fp1;
char *fname,ch[20];
clrscr();
printf("\n enter source file name\t");
gets(fname);
fp1=fopen(fname,"w");
if(fp1==NULL)
{
printf("\n unable to open\n");
exit(0);
}
printf("\n enter the data:");
scanf("%s",ch);
fprintf(fp1,"%s",ch);
fflush(stdin);
printf("\n data store in %s",fname);
fclose(fp1);
getch();
}
UNION (by using Array Function):
ReplyDelete-------------------------------------------------
#include
void dubremove(int arr[],int n);
void swaping(int x[],int m);
int jl=0,arr[100],org[100],j2=0,n,m=0,i=0,j=0,t=0,org1[100],m1=0;
void main()
{
int arr1[100],arr2[100],n1;
printf("\nEnter the size of array\n");
scanf("%d",&n1);
printf("\nEnter the first array\n");
for(i=0;i=2)
org1[m1++]=arr[i];
else
org[m++]=arr[i];
}
}
if(jl>=2)
swaping(org1,m1);
else
swaping(org,m);
jl++;
}
void swaping(int org[],int m)
{
for(i=0;iorg[j])
{
t=org[i];
org[i]=org[j];
org[j]=t;
}
}
}
if(j2>=2)
{
printf("\nResult of Union\n");
for(j=0;j<m;j++)
printf("%d ",org[j]);
}
j2++;
}