Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Simple C program file input/output int main(int argc , char*argv[]): char*argv[] contains the input file name if the file name is not provided then display

Simple C program file input/output

int main(int argc , char*argv[]):char*argv[] contains the input file name if the file name is not provided then display the error message. If unable to open the file (in case of wrong file name) then also display (different) error message.

Here are some hints for error handling

If argc value is not equal to 2 that means file name is not provided by the user.

If file pointer has a value NULL (after fopen call) that means file could not be opened successfully.

int read_info(char *, int *): This function takes a file name to read the input from and an integer array to store the input from the file. It returns the size of the input which is the basically the number at the first line of the input file (see below).This function opens the input text file if unable to open return -1 or any negative indicating unable to open the file that can be used in the main to display the error message. If able to open the input file successfully then return the size of the input.

Sample input file

5

112

335

421

611

220

Here 5 is the size of the input. Read this number first (using fscanf function). Then use it to run a loop to read the input from the file and store them in the integer array.

Again there are multiple ways to read input from a file above suggestion is just one way. You are free to read input from the file using any other function /method.

void printArray(int *, int ) -This function prints the content of the integer array. It takes an integer array and the size of the input.

Note

Implement the pre-lab using the function prototype as given in the document. They are sufficient and should not be modified for the pre-lab.

Dont use any global variable in the implementation.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions