Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Linux and C. Below is the the skeleton C file. but the question i posted below as a picture. /* Cmpt 214 Assignment 2 Question

Linux and C. Below is the the skeleton C file. but the question i posted below as a picture.

/* Cmpt 214 Assignment 2 Question 3 */ /* Name, Student Number, NSID */ #include  /* Global variables. Accessible from all functions. */ int global_count = 0; /* Function prototypes. */ int strlen_iter( char* string ); int strlen_recursive_return( char* string ); int strlen_recursive_global( char* string, int accum ); /* Main function. */ int main( int argc, char* argv[] ) { char *input_string; int string_length; // if a command-line argument was given, process it if( argc > 1 ) { input_string = argv[1]; printf( "input string: '%s' ", input_string ); string_length = strlen_iter( input_string ); printf( "Calculating string length iteratively: %d ", string_length ); string_length = strlen_recursive_return( input_string ); printf( "Calculating string length recursively returning a value: %d ", string_length ); if( strlen_recursive_global( input_string, 0 ) ) { printf( "Calculating string length recursively " ); printf( "using a global variable: %d ", global_count ); } } // done return 0; } /* * your definitions of strlen_iter( char* string ), * strlen_recursive_return( char* string ), and * strlen_recursive_global( char* string, int accum ) go here */ 

image text in transcribed

3. In this question you will write a simple function for determining the length of a C string in three different ways. We have provided a skeleton C file and Makefile to get you started. Download them and place them in a new subdirectory. Within the skeleton C file a n() function has been rovided for ou. You obis to mplement function prototypes at the beginning of the file. Add your function implementations below the main function. Make sure to test your resultant program The functions you need to write are as follows int strlen_iter char* string)i he3n tions declined in the This function calculates the length of a string iteratively using some sort of loop int strlen_recursive_return char* string This function calculates the length of a string by recursively calling itself with a substring (of the original string) which is one character shorter. It then returns a value of one plus the length of the substring. int strlen_recursive global char string, int accum); This function calculates the length of a string by calling itself recursively on a substring one character shorter than the original string and the second argument incremented by one That is, the recursive call of the function will be strlen_recursive global( string+1, accumt ). On reaching the base case, the function will not make a recursive call. Instead it will store the value of the second function argument, aceum, in the global variable global count. The function returns 1 (true) on successful operation, and 0 (false) on error. For this question, hand in your commented source code in string_length.e and an annotated test log. Instead of an annotated test log, you can submit a raw test log (no annotations) and a separate file with testing documentation (e.g. test plan, results description, conclusion Notes o Keep the function prototypes at the top of the file and implement the functions beloW main) o Everything has been provided for you in the the skeleton C file. You only need to implement the functions. Do not modify the original code in any way o You don't need to include any other header files You shouldn't need to modify your Makefile. Just use the make command; i.e. make sure that your current working directory is the one with the Makefile provided and type the command "make". If compilation was successful, a binary called a.out will be created in your local directory. To test your program, use commands of the form "./a.out string" where string is an arbitrary string; for example ./a.out testing 1 23 Make sure to try a variety of strings, including the null string, and check that the answer given by your program in each case is correct

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

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions