Table of Contents
Background – Introduction and my_strlen 5
Problem 1 – Creating Your Own Library of String Functions 6
Problem 2 – Adding Non-Standard String Functions to Your Library 8
Problem 3 – Parsing Strings 11
The sscan and sprintf functions 11
Problem 4 (Extra Credit) – my_strtok 14
Important Notes on Plagiarism 18
In lecture you have learned that in C an array of characters with a NULL termination is considered a String, whereas an array of characters without a NULL termination is simply an array of characters. The standard library <string.h> is available with most C compilers that includes several functions designed to work with and manipulate Strings in C. Strings are so common in C that knowing how to use these functions in C is considered a basic skill.
The goal of this assignment is to give you experience with strings in C and with the library of functions designed to work with strings, give you an appreciation of how those functions work, and also continue to help you work with pointers and arrays (in the context of C Strings).
We have provided a basic framework and several function definitions that you must implement.
This file contains the function declarations you must implement. Aside from adding the required declarations for my_strrev, my_strccase, and optionally my_strtok, do not modify this file.
This file contains empty implementations for the functions defined in my_string.h. We have provided the implementations of my_strlen using array notation and pointer arithmetic for you. You will provide the remaining implementations in this file.
This is a test environment program only. We will not review it or even look at it and it will not be used for grading. You are free to write any code necessary to test your implementations.
In lecture, we discussed a commonly used function, strlen, that is part of the string.h library. Its job is to take in a C String, count the number of characters up to (but not including) the NULL character and return the string’s length. As an example, if our string was
char my_string [100] = “Tom” ;
strlen(my_string) would return 3.
Even though there are 100 bytes allocated on the stack for the string, since there are only 3 characters (followed by a NULL), the length of the string is indeed 3.
In lecture, we presented two versions of a strlen-like function. One function uses array notation and the other uses pointer notation. Ultimately they perform the same operation.
my_strlen_array treats the incoming argument (char* string) as if it is an array using array notation (i.e. with square brackets [ and ])
size_t my_strlen_array(const char *str)
int len = 0 ;
while (str[len] != ‘’) {
len++ ;
}
return (len) ;
}
my_strlen_pointer treats the incoming argument as the pointer it truly is, using pointer arithmetic to determine the string’s length.
size_t my_strlen_pointer(const char *str)
const char* s;
for (s = str; *s; ++s) ;
return (s – str);
}
Note: size_t is not an actual C type; is a “typedef’ed”, that is, it is a shortcut for unsigned long.
Your task for this assignment is to implement your own library of string functions to mimic the standard C library string functions.
In Codio, we have provided a header file called my_string.h. In that header file, we have declared several functions: my_strlen_array, my_strcpy_pointer, etc.
In my_string.c, we have implemented only two of the many functions: my_strlen_array and my_strlen_pointer, as described above. You will implement the remaining functions.
In a third file: program1.c, we have provided some basic code that calls the functions in your my_string library and compares the output of them to functions in the standard C-library string.h. This is one way to quickly check if your output is correct. Look carefully at these three files before continuing.
For this problem, your task is to implement your own library of string functions to mimic the standard C library string functions.
int main (int argc, char** argv) ;
int main (int argc, char** argv) {
printf (“# of arguments passed: %d
”, argc) ;
for (int i=0; i< argc ; i++) {
printf ( “argv[%d] = %s
”, i, argv[i] ) ;
}
return (0) ;
}
./program3 arg1 2 arg3 4 arg5
There is a single “submission check” test that runs once you upload your code to Gradescope. This test checks that you have submitted all required files and also that your program compiles and any autograder code compiles successfully. It does not run your program or provide any input on whether it works or not. This check just ensures that all the required components exist. This test is performed after uploading to Gradescope.
Ensure that you are passing this check before closing Gradescope. If you are not passing this check, please reach out to TAs for troubleshooting assistance.
The autograder will also show the results of six tests:
The remaining tests will be hidden until after grades are published.
You will submit this assignment to Gradescope in the assignment entitled Assignment 10: Strings in C.
Download the required .c source and .h header files (as well as any additional helper files required) and your Makefile from Codio to your computer, then Upload all of these files to the Gradescope assignment. We expect my_string.c, my_string.h, program3.c, and makefile. Do not submit program1.c, program2.c., or program4.c.
Do not not submit intermediate files (anything .o).
You have unlimited submissions until the deadline, after which late penalties apply as noted in the syllabus.
We will only grade the last submission uploaded.
Do not mark your Codio workspace complete. Only the submission in Gradescope will be used for grading purposes.
There is no page matching and no academic integrity submission for autograder assignments.
This assignment is worth 127.5 points, normalized to 100% for gradebook purposes.
Problem 1 (standard functions) is worth 72 points (each function is 9 points, with equally weighted sub-tests per function).
Problem 2 (custom functions) is worth 18 points (each function is 9 points, with equally weighted sub-tests per function).
Problem 3 (parsing strings) is worth 10 points.
Problems 1, 2, and the Extra Credit are tested with Unit Testing. We will run different scenarios for each function to validate the functionality (partial credit based on which tests fail).
Problem 3 checks the final output produced by your program and compares that output to the expected output. It must match exactly for credit: double check that your program does not have any extra output.
We will only grade the last submission, regardless of the results of any previous submission.
We will not be providing partial credit for autograder tests.
You may ask for feedback by submitting a regrade request using the Miscellaneous Adjustments rubric item.
The Extra Credit is worth 6 percentage points so the highest grade on the assignment is 106%.
Your extra credit must not break functionality for the non-extra credit requirements.
There is no partial credit. It must work completely for any credit.
We will not give guidance on how to do this since it is designed to be challenge problem.
Hints from previous semesters
strlen reference
https://www.tutorialspoint.com/c_standard_library/c_function_strlen.htm
strcpy reference
https://www.tutorialspoint.com/c_standard_library/c_function_strcpy.htm
strchr reference
https://www.tutorialspoint.com/c_standard_library/c_function_strchr.htm
strcat reference
https://www.tutorialspoint.com/c_standard_library/c_function_strcat.htm
strcmp reference
https://www.tutorialspoint.com/c_standard_library/c_function_strcmp.htm
sscanf reference
https://www.tutorialspoint.com/c_standard_library/c_function_sscanf.htm
sprintf reference
https://www.tutorialspoint.com/c_standard_library/c_function_sprintf.htm
strtok reference
https://www.tutorialspoint.com/c_standard_library/c_function_strtok.htm
strtok reference (Linux manual pages)
https://man7.org/linux/man-pages/man3/strtok_r.3.html
The const modifier
http://www.geeksforgeeks.org/const-qualifier-in-c/
Reviews
There are no reviews yet.