MA 511: Computer Programming: Partha Sarathi Mandal
MA 511: Computer Programming: Partha Sarathi Mandal
#include <stdio.h>
main(){
FILE *fp;
int i;
fp = fopen("output.dat", "w");
if(fp==NULL)
printf("Error for opening a file\n");
for(i=65; i<90; i++)
fprintf(fp, "%c\n", i);
fclose(fp);
}
output.dat
A
B
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
#include <stdio.h>
main(){
FILE *fp1;
char ch;
fp1 = fopen("output.dat", "r");
if(fp1==NULL)
printf("Error for opening a file\n");
else{
while(!feof(fp1)){
fscanf(fp1, "%c", &ch);
printf("%c",ch);
}
}
fclose(fp1);
}
Assignment
• Write a C program for inserting an integer before
a given target value in a given array of integer.
• Write a C program for deleting a given value in a
given array of integer.
• Write a C program for (i) writing integers 1-100 to
a file (fwrite.dat) (ii) read data from the file
fwrite.dat, identify numbers which are perfect
square and write over a new file (newfile.dat).