Short answer Name Exam 2 For 712 give a brief description o

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

Solution

#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.
}

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 mi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site