Sale!

Project [8]: Pointers and Strings

Original price was: $35.00.Current price is: $30.00.

Category:
Rate this product

Project [8]: Pointers and Strings

Project Goals
The goals of this project are to:
• Get students familiar with the use of pointers
• Get students familiar with strings
Important Notes:
1. Formatting: Make sure that you follow the precise recommendations for the output content and
formatting: for example, do not change the text of the problem from “Enter the first string: ” to
“Enter string: ”. Your assignment will be auto-graded and any change in formatting will result in a loss
in the grade.
2. Comments: Header comments are required on all files, for each function, and recommended throughout
the rest of the program. Points will be deducted if no header/function comments are included.
3. Restriction: The use of goto statements anywhere within this program is prohibited. Points will be
deducted if goto is used.
Problem 1
Write a program that implements four of the string library functions using pointers: strcopy (string copy),
strconcat (string concatenate), strcomp (string compare), and strlength (string length). First, the program will
ask the user to enter two strings with a maximum of 20 characters each. The program will then output the length of
each string. Then, it will output which string comes first alphabetically. The program will then add string 1 to string
2 and output the two strings. Finally, the program will copy string 1 into string 2 and print the two strings again.
Your program should:
1. Using the strlength function, calculate and print out the length of each string.
2. Using the strcomp function, print out which string comes first alphabetically.
1. If the strings are the same your program should print out: “The two strings are the same.”
2. If string 1 comes first alphabetically your program should print out: “String 1 comes before
string 2 alphabetically.”
3. If string 2 comes first alphabetically your program should print out: “String 2 comes before
string 1 alphabetically.”
3. Using the strconcat function, add string 1 to the end of string 2 and print out string 1 and 2
4. Using the strcopy function, copy string 1 into string 2 and print out string 1 and 2
The program should function as follows (items underlined are to be entered by the user):
Please enter the first string: jackhammer
Please enter the second string: Jacky
The length of string 1 is: 10
The length of string 2 is: 5
String 1 comes before string 2 alphabetically.
String 1 after concatenation: jackhammer
String 2 after concatenation: Jackyjackhammer
String 1 after copying: jackhammer
String 2 after copying: jackhammer
Your program should implement and use the following functions:
• strlength: This function will take as a parameter a character pointer to a string. It will return the length
of the string, not including the null terminator.
• strcopy: This function should take as parameters two character pointers to two strings (a destination
string and a source string in that order). Then it will copy the source string into the destination string,
including the null terminator. It will then return a pointer to the beginning of the destination string.
• strconcat: This function should take as parameters two character pointers to two strings (a destination
string and a source string in that order). Then it will add the source string to the end of the destination
string. It will then return a pointer to the beginning of the destination string.
• strcomp: This function will take as parameters two character pointers to two strings (string 1 and string
2 in that order). The function then compares the two strings and if string 1 comes first alphabetically it
returns 1. If the string 2 comes first alphabetically then it returns -1. If the strings are the same, then the
function returns 0. The function should compare the two strings one character at a time and return the
appropriate value as soon as a difference is noticed between the strings.
Note:
• You may NOT include the string library. The point of this project is to get students to work with pointers
and their use in strings. Inclusion of the string library will result in a grade of zero for this project. (You
must write all the functions yourself)
• Your functions must use pointers and pointer arithmetic. You are not allowed to use square brackets to
move along the strings.
• You can assume that all strings will be just alphabetic characters. The strings will not contain any spaces.
Save your program as strings.c
Grading Rubric
Grading will be done for each problem as follows:
Correctly-named file 5%
Header comment 2%
Program compiles 5%
Correctly-reading data from terminal 28%
Correct result printed 60%
Submission details
To submit your project, you will have to use the submission script. You do this by either:
1. Working on an ECC machine
2. Working on the provided VMware
3. Secure Copying your files (See Mac Support for information)
To Submit your project:
• Have a directory called “project8”
• Save your *.c files in that directory
• To submit: (don’t type the ‘>’ symbols)
> cd project8
> submit
The submission script copies all files in the current directory to our directory. You may submit as many times as you
like before the deadline, we only keep the last submission.
Academic Honesty
Academic dishonesty is against university as well as the system community standards. Academic dishonesty
includes, but is not limited to, the following:
Plagiarism: defined as submitting the language, ideas, thoughts or work of another as one’s own; or assisting in the act
of plagiarism by allowing one’s work to be used in this fashion.
Cheating: defined as (1) obtaining or providing unauthorized information during an examination through verbal,
visual or unauthorized use of books, notes, text and other materials; (2) obtaining or providing information
concerning all or part of an examination prior to that examination; (3) taking an examination for another student, or
arranging for another person to take an exam in one’s place; (4) altering or changing test answers after submittal for
grading, grades after grades have been awarded, or other academic records once these are official.
Cheating, plagiarism or otherwise obtaining grades under false pretenses” constitute academic
dishonesty according to the code of this university. Academic dishonesty will not be tolerated and
penalties can include cancelling a student’s enrolment without a grade, giving an F for the course, or for the
assignment. For more details, see the University of Nevada, Reno General Catalog.

Scroll to Top