//10A
#include <stdio.h>
#include <stdlib.h>
int main()
char str[1000];
FILE *fptr;
char fname[20]="test";
printf("\n\n Create a file (test.txt) and input text :\n");
printf("----------------------------------------------\n");
fptr=fopen(fname,"w");
if(fptr==NULL)
printf(" Error in opening file!");
exit(1);
printf(" Input a sentence for the file : ");
fgets(str, sizeof str, stdin);
fprintf(fptr,"%s",str);
fclose(fptr);
printf("\n The file %s created successfully...!!\n\n",fname);
return 0;
}
//10B
#include <stdio.h>
#include <stdlib.h>
int main()
char str[1000];
FILE *fptr;
char fname[20]="test";
printf("\n\n Create a file (test) and input text :\n");
printf("----------------------------------------------\n");
fptr=fopen(fname,"w");
if(fptr==NULL)
printf(" Error in opening file!");
exit(1);
printf(" Input a sentence for the file : ");
fgets(str, sizeof str, stdin);
fprintf(fptr,"%s",str);
fclose(fptr);
printf("\n The file %s created successfully...!!\n\n",fname);
fptr=fopen(fname,"r");
if(fptr==NULL)
printf(" Error in opening file!");
exit(1);
printf(" Output a sentence for the file : ");
printf("%s",str);
return 0;
}
#include<stdio.h>
main()
FILE *f1, *f2, *f3;
int number , i;
printf("Contents of Data File \n\n");
f1 = fopen("C:\\Users\\STUDENTS\\Desktop\\PRASHIK\\DATA","w");
for(i=1;i<=10;i++)
scanf("%d",&number);
if (number == -1) break;
putw(number,f1);
fclose(f1);
f1 = fopen("C:\\Users\\STUDENTS\\Desktop\\PRASHIK\\DATA","r");
f2 = fopen("C:\\Users\\STUDENTS\\Desktop\\PRASHIK\\ODD","w");
f3 = fopen("C:\\Users\\STUDENTS\\Desktop\\PRASHIK\\EVEN","w");
while ((number = getw(f1)) != EOF)
if(number % 2 == 0)
putw(number,f3);
else
putw(number, f2);
}
fclose(f1);
fclose(f2);
fclose(f3);
f2 = fopen("C:\\Users\\STUDENTS\\Desktop\\PRASHIK\\ODD","r");
f3 = fopen("C:\\Users\\STUDENTS\\Desktop\\PRASHIK\\EVEN","r");
printf("\nContents of ODD file \n");
while((number = getw(f2)) != EOF)
printf(" %d", number);
printf("\nContents of EVEN file \n");
while((number = getw(f3)) != EOF)
printf(" %d", number);
fclose(f2);
fclose(f3);