Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!