Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

#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])); }

image text in transcribed

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 .out .bkp .dot .tx For example, if the file name is memo.txt , the function will return 0. If the file name is memo.tx.dot , the 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, strcmp, 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

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

Microsoft Outlook 2023

Authors: James Holler

1st Edition

B0BP9P1VWJ, 979-8367217322

More Books

Students also viewed these Databases questions

Question

Prepare for a successful job interview.

Answered: 1 week ago

Question

Describe barriers to effective listening.

Answered: 1 week ago

Question

List the guidelines for effective listening.

Answered: 1 week ago