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

Write a void function definition called OpenInputFile that performs the actions

ID: 3573456 • Letter: W

Question

Write a void function definition called OpenInputFile that performs the actions listed. The function is to use one parameter - an input file stream Once a file is successfully opened by the function, control is returned to main a) Prompt the user for the name of an input file and read it. b) Open the file. c) While the file does not open successfully: print out a message stating as such, reset the input stream variable. The code to reset the file stream variable inFile is inFile. clear (); Prompt the user for the name of an input file and read it Open the file

Explanation / Answer

a)giving input file and reading it into file:

program:

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

int main()

{

char ch[500];

FILE DATA*ptr;

if((ptr=fopen("data.txt","r"))==NULL)

{

printf("error message! opening file);

exit(0);

}

fscan(ptr,%/n,c);

printf("reading the elements of the file: %s",c);

fclose(ptr);

return 0;

Suppose the data.txt following text information

Hai john what are you doing

how is your life.

how is your wife.

then

.reading the elements from the file:Hai jhon what are you doing.

b)open the file

program:

#include<stdio.h>

#include<conio.h>

int main()

{

NEW FILE*fp;

fp=fopen("data.txt","d");

return 0;

}

C)

program:

#include<stdio.h>

#include<conio.h>

main()

{

int number;

FILE*fp;

do

{

printf(" enter the file path:");

sacnf("%d",&file);

fileName.open(file.c_str());

if(fileName.fail())

{

printf("error message!");

fileName.clear();

}

}

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