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