Choose the c methods applicable for reading to a text file from the items given below:
(a) get ()
(b) close ()
(c) getw()
(d) fread()
fill in the missing:
Assume the following program snippet writes to text file:
int main() {
FILE * ptr;
int num;
_____________________= fopen("d:\\writingTo_File.txt", "");_________________
if (ptr !=___________________) {
printf("File created successfully!\n");
}
else {
printf("Failed to create the file.\n");
// exit status that an error occurred
return -1;
}
#include <stdio.h>
int main() {
FILE * fp;
fp = fopen ("d:\\music.txt", "w");
fprintf (fp ,"Engineering Programming");
fclose(____________);
return______________;
}
Assume the following piece of code reads from a text file
int main() {
int sum =0;
FILE * ptr;
ptr = fopen("d:\\students.________","___________");
if (ptr ==NULL){
_______________("file does not exist!!");
exit(0);
}
getw()
int main() {
FILE * ptr;
int num;
ptr = fopen("d:\\writingTo_File.txt", "");
if (ptr != nullptr) {
printf("File created successfully!\n");
} else {
printf("Failed to create the file.\n");
}
// exit status that an error occurred
return -1;
}
#include <stdio.h>
int main() {
FILE * fp;
fp = fopen ("d:\\music.txt", "w");
fprintf (fp ,"Engineering Programming");
fclose(fp);
return 0;
}
int main() {
int sum =0;
FILE * ptr;
ptr = fopen("d:\\students.txt","r");
if (ptr ==NULL){
printf("file does not exist!!");
exit(0);
}
Comments
Leave a comment