Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***This is provided file: get_extension.c #include #define MAX_SIZE 20 int get_extension(const char *file_name); int main(int argc, char* argv[]){ //simplifying things and not doing any argument

image text in transcribed

***This is provided file: get_extension.c

#include

#define MAX_SIZE 20

int get_extension(const char *file_name);

int main(int argc, char* argv[]){ //simplifying things and not doing any argument validation printf("The extension of the input file is: %s ", get_extension(argv[1])); }

This exercise is based on a combination of Exercise 12 from Ch12 and Programming Project 18 from Ch13 You are provided a file called get_extension.c that has the following function prototype int get_extension (const char *file_name): where file_name is a string containing a file name. Your task is to implement this function as follows: The function processes the passed file name to find the file extension and returns the index of this file extension from a lookup array called extensions The function must declare extensions as a static array of pointers to strings that stores the different file extensions in the following order: txt .bkp .tx function will return 3. If the file name doesn't have an extension, the function will return -1. Keep the function as simple as possible by having it use functions from the string library such as strlen, strncpy stremp, etc. To test your get_extension function, the provided program's main function takes the file name as a program argument and passes it to get_extension - The main function then prints the value returned by get_extension to stdout You can safely assume that the program will always be provided with an argument. You do not need to do any argument validation for this exercise. You can assume that the file name will have at most 20 characters including the extension. Files that need to be on GitHub: Makefile to compile the program

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

Oracle 12c SQL

Authors: Joan Casteel

3rd edition

1305251032, 978-1305251038

More Books

Students also viewed these Databases questions

Question

5. What information would the team members need?

Answered: 1 week ago

Question

Where those not participating, encouraged to participate?

Answered: 1 week ago

Question

Were all members comfortable brainstorming in front of each other?

Answered: 1 week ago