This is another short assignment to give you more practice with NUL-terminated strings, functions, iteration, and other cool stuff. The program you write will scan and manipulate strings. There are four functions that you need to implement to complete the assignment:

Function Description
int count_tabs(char const *string) Given a string, count the number of tabs in the string and return the
count.
int substitute_char(char *string,
old_char,
char new_char);
Given a string, substitute old_char with new_char. Returns the number of substitutions
void calculate_lengths( char const *string,
tabsize,
string_length,
int *display_length);
Given a string and a tab size, calculate the length of the string and the display or print length of the string. Display length is the number of characters required to display the string after tabs are expanded into spaces.

Notes:

  • You can assume that all of the strings are properly NUL-terminated so the length is not passed to the functions.
  • There is a mystrlen() function implemented in scantext.c. This file included for you to use, if you need.
  • The function calculate_lengths() takes two integer pointers. These pointers are used to return the values to the calling function (main(), in this case).
  • Functions are roughly listed in the above table in increasing order of difficulty. Therefore, you should work on the functions in the listed order.
  • If you wish to write additional "helper" functions to implement the above functions, they must be marked with the static keyword (like the mystrlen () function that is provided).

Details

You are given a file called driver.c , which includes the main () function and several test cases for you to use. You are also given a header file called scantext.h and a C source file called scantext.c . You are not to change the header file in any manner. There are four functions prototyped in the header file, one for each of the functions you are to write. As always, you must implement these functions exactly as prototyped in the partially implemented scantext.c. A sample command line to compile this assignment looks like this:

gcc -O -Wall -Werror -ansi -pedantic driver.c scantext.c -o scantext.exe

This will compile and link both files and produce an executable file named scantext.exe. This assignment will not require you to include any header files in your code - so do not. You don't even need to include scantext.h . Since you will be submitting only scantext.c , ensure that you write all your code only in this file.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.