Answer to Question #255199 in C for Blacksun

Question #255199

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);
}
1
Expert's answer
2021-10-22T16:44:14-0400

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);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS