Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Language program. Please follow the instructions given. Must use functions, pointers, and File I/O. Thank you. Use the given function to create the program

C Language program. Please follow the instructions given. Must use functions, pointers, and File I/O. Thank you.

Use the given function to create the program shown in the sample run. Your program should find the name of the file that is always given after the word filename (see the command line in the sample run), open the file and print to screen the contents. The type of info held in the file is noted by the word after the filename: string or numbers. If the word filename is not found on the command line, the program should let the user know and exit. You can assume that if the word filename is found on the command line, it is always followed by the name of a file and the word string or numbers. YOU MUST USE THE FUNCTION GIVEN. 0 POINTS IF FUNCTION IS MODIFIED OR UNUSED.

/*This function takes a char** pointer and integer. It returns a -1 if the word filename is not found in the char** pointer and any other value otherwise.*/

int find_filename(int n, char **b)

{

int i;

int counter=0; /*equals -1 if didnt find*/

int check=0;

for(i=0;i

{

if(strcmp(*b, "filename")==0)

{

check=1;

}

counter++;

b++;

}

if(check!=1)

{

counter=0;

}

return (counter-1);

}

Sample Run 1:

computer$ ./a.out random filename stuff.txt string

Filename: stuff.txt

We're dealing with string info.

Contents of the file:

hello world!

I am here to say that

it is a sunny day.

Sample Run 2:

computer$ ./a.out filename nums.txt numbers

Filename: nums.txt

We're dealing with number info.

Contents of the file:

2

3

4

5

6

7

Sample Run 3:

computer$ ./a.out just numbers words

No filename given. Bye!

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

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

Explain how a cloud architecture works.

Answered: 1 week ago