Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Short answer ? Name:, Exam 2 For 7-12 give a brief description of what each of t

ID: 3936584 • Letter: S

Question

Short answer ? Name:, Exam 2 For 7-12 give a brief description of what each of these functions would do (most kely crash is something some of these functions might do) (2 points) void runlo int a; FILE "file = fopen("imputnt","r"); fscanf"input.t,"d, sa) 8) (4 points void run20 int a; FILE file fopen("input.xt"."w ficant( file, "%d", &a;); 9) (4 points) void run30 int a; FILE .fik-fopen("input.Da","a"); fprinti file, "%d", &a;); 10) ( 4 points void run40 int a FILE "file fopen("input.txr"r fscanf(file, "%d", &a;);

Explanation / Answer

#include <stdio.h>
void run1()
{
int a;       //Declares a variable a.
FILE *file = fopen("input.txt", "r");   //Defines a file pointer file in read mode.
fscanf("input.txt", "%d", &a);       //This leads to error, as fscanf() 1st parameter should be a file pointer and not a character array.
}

void run2()  
{
int a;       //Declares a variable a.  
FILE *file = fopen("input.txt", "w");   //Defines a file pointer file in write mode.
fscanf(file, "%d", &a);       //This leads to error, as fscanf() will read a file but it is opened in write mode.
}

void run3()
{
int a;       //Declares a variable a.
FILE *file = fopen("input.txt", "a");   //Defines a file pointer file in append mode.
fprintf(file, "%d", &a);   //This appends the address of the variable a to the file input.txt.
}

void run4()
{
int a;       //Declares a variable a.
FILE *file = fopen("input.txt", "r");   //Defines a file pointer file in read mode.
fscanf(file, "%d", &a);   //This reads an integer from the file pointer file into a variable a.
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote