In this homework assignment, you must define a number of functions that can be used to analyze and manipulate C-strings

Project Description Before C++ and classes, strings were stored in simple arrays of characters. The term C-string refers to the classic implementation of strings in the C programming language. A C-string is a sequence of characters terminated by the null character, ‘’. Since C is part of C++, C-string implementations are valid in C++ as well as C.

Recall that an array of characters is the underlying data structure for storing C-strings. For example, this definition creates such an array.

Haven’t Found The Relevant Content? Hire a Subject Expert to Help You With
In this homework assignment, you must define a number of functions that can be used to analyze and manipulate C-strings
Post Your Own Question And Get A Custom Answer
Hire Writer

char myString[100];myString will be capable of holding a C-string with up to 99 characters before the terminating null character. Of course, myString can hold a shorter C-string, too. For example, these assignments give myString the value “xyz”.

myString[0] = ‘x’;myString[1] = ‘y’;myString[2] = ‘z’;myString[3] = ‘’;It is legal to initialize a string variable, like this.

char example[100] = “First value”;Now, the string example[100] contains the following:————————————————————–| F | i | r | s | t | | v | a | l | u | e | | * | * |…————————————————————–However, it is not legal to assign string variables, because you cannot assign to an entire array.

myString = “xyz”; // ILLEGAL: Cannot assign to an arrayFurthermore, you cannot do comparisons like this.

if (myString == “xyz”) cout << “fantasy land” << endl; The comparison myString == “xyz” is actually legal (it will compile the addresses, not the strings!), but it will always evaluate to false. To handle these kinds of difficulties, programmers can rely on the C-string library (also referred to as ). This library, which is part of every proper C++ installation, is an extensive collection of functions for handling C-strings. Following are the 4 basic string library functions that we’ll discuss:

(1) strlen(str)Returns the number of characters in the string, not including the null character.

(2) strcmp(str1, str2)This function takes two strings and compares them. If the strings are equal, it returns 0. If the first is greater than the 2nd, then it returns some value greater than 0. If the first is less than the 2nd, then it returns some value less than 0.

You might use strcmp() as in:

#include char str1[] = “garden”;if (strcmp(str1, “apple”) == 0)  cout << “Equal” << endl;else  cout << “Not equal” << endl;or

if (strcmp(str1, “eden”) > 0) cout << “‘” << str1 << “‘ comes after ‘eden'” << endl;

The ordering for strings is lexical order based on the ASCII value of characters. Remember that the ASCII value of ‘A’ and ‘a’ (i.e., upper/lowercase) are not the same.

An easy way to remember how to use strcmp() to compare 2 strings (let’s say a and b) is to use the following mnemonics:Want… Use…a == b strcmp(a, b) == 0a < b strcmp(a, b) < 0a >= b strcmp(a, b) >= 0… …

(3) strcpy(dest, source)Copies the contents of source into dest, as in:

#include

char str1[10] = “initvalue”;strcpy(str1, “second”); Now, the string str1 contains the following:——————————————-| s | e | c | o | n | d | | u | e | |——————————————-and the word “initvalue” has been overwritten. Note that it is the first null character () that determines the end of the string. When using strcpy(), make sure the destination is big enough to hold the new string.

Note: An easy way to remember that the destination comes first is because the order is the same as for assignment, e.g:dest = sourceAlso, strcpy() returns the destination string, but that return value is often ignored.

(4) strcat(dest, source)Copies the contents of source onto the end of dest, as in:

#include char str2[10] = “first”;strcat(str2, ” one”);Now, the string str2 contains the following:——————————————| f | i | r | s | t | | o | n | e | |——————————————When using strcat(), make sure the destination is big enough to hold the extra characters.

Note: Function strcat() also returns the destination string, but that return value is often ignored.

Assignment DirectionsYour task in this assignment is to complete your own versions of these four most commonly used standard string functions.

Your version:int mystrlen( const char *s)int mystrcmp( const char *s1, const char *s2)char *mystrcpy( char *s1, const char *s2)char *mystrcat( char *s1, const char *s2)C standard string library functions:int strlen( const char *s)int strcmp( const char *s1, const char *s2)char *strcpy( char *s1, const char *s2)char *strcat( char *s1, const char *s2)Each of your functions should have the same behavior as the corresponding above C standard string function. For example, your mystrlen function should have the same behavior as the C standard strlen function.

Your functions should not call any of the standard string functions. In the context of this assignment, you should pretend that the standard string functions do not exist.

You should pay special attention to boundary cases. In particular, make sure that your functions work when given empty strings as arguments. For example, make sure that the function call mystrlen(“”) returns 0.

First create a header file named mystring.h containing the interface to your functions. The interface should consist of a set of function declarations. Then create a file named mystring.cpp containing the implementation of your functions, that is, a set of function definitions. It should “#include” the interface file to insure that each function definition is consistent with its declaration.

You may use array notation to define your functions. For example, this is an acceptable version of the mystrlen function:

int mystrlen(const char pcString[]){ int Length = 0; while (pcString[Length] != ‘’) Length++; return Length;}However we encourage you to use pointer notation instead of array notation to define your functions; pointer notation is used heavily throughout the course, and it would be wise to use this assignment to insure that you are comfortable with it. For example, we encourage you to define your mystrlen function similar to this:

int mystrlen(const char *pcString){ const char *pcStringEnd = pcString; while (*pcStringEnd != ‘’) pcStringEnd++; return pcStringEnd – pcString;}The comment should appear in both the .h file (for the sake of the users of the function) and the .cpp file (for the sake of the implementation of the function).

For example, here is an appropriate way to comment a mystrlen function:

In file mystring.h:…int mystrlen(const char *pcString);/* Return the length of string pcString. */…In file mystring.cpp:…int mystrlen(const char *pcString) /* Return the length of string pcString. */ { …}…Note that the comment explicitly states what the function returns, and explicitly refers to the function’s parameter (pcString).

Calculate the price of your order

Select your paper details and see how much our professional writing services will cost.

We`ll send you the first draft for approval by at
Price: $36
  • Freebies
  • Format
  • Formatting (MLA, APA, Chicago, custom, etc.)
  • Title page & bibliography
  • 24/7 customer support
  • Amendments to your paper when they are needed
  • Chat with your writer
  • 275 word/double-spaced page
  • 12 point Arial/Times New Roman
  • Double, single, and custom spacing
  • We care about originality

    Our custom human-written papers from top essay writers are always free from plagiarism.

  • We protect your privacy

    Your data and payment info stay secured every time you get our help from an essay writer.

  • You control your money

    Your money is safe with us. If your plans change, you can get it sent back to your card.

How it works

  1. 1
    You give us the details
    Complete a brief order form to tell us what kind of paper you need.
  2. 2
    We find you a top writer
    One of the best experts in your discipline starts working on your essay.
  3. 3
    You get the paper done
    Enjoy writing that meets your demands and high academic standards!

Samples from our advanced writers

Check out some essay pieces from our best essay writers before your place an order. They will help you better understand what our service can do for you.

Get your own paper from top experts

Order now

Perks of our essay writing service

We offer more than just hand-crafted papers customized for you. Here are more of our greatest perks.

  • Swift delivery
    Our writing service can deliver your short and urgent papers in just 4 hours!
  • Professional touch
    We find you a pro writer who knows all the ins and outs of your subject.
  • Easy order placing/tracking
    Create a new order and check on its progress at any time in your dashboard.
  • Help with any kind of paper
    Need a PhD thesis, research project, or a two-page essay? For you, we can do it all.
  • Experts in 80+ subjects
    Our pro writers can help you with anything, from nursing to business studies.
  • Calculations and code
    We also do math, write code, and solve problems in 30+ STEM disciplines.

Frequently asked questions

Get instant answers to the questions that students ask most often.

See full FAQ
  • What if I’m dissatisfied with the paper I get?

    The average quality score at our professional custom essay writing service is 8.5 out of 10. The high satisfaction rate is set by our Quality Control Department, which checks all papers before submission. The final check includes:
    • Compliance with initial order details.
    • Plagiarism.
    • Proper referencing.
    If for some reason we happen to leave a mistake unnoticed, you are invited to request unlimited revisions of your custom-written paper. For more information, check our Revision Policy. We will do our best to make your experience with Familiar Essays enjoyable.
  • I need an essay on the same day. Is it something you can do?

    Sure. Our writing company offers a fast service with an 8-hour deadline for orders up to master’s level. Make sure to specify the deadline in the order form and our writers will write a paper within the indicated timeslot. Just proceed to submit your requirements here Once you order a custom-written essay, our managers will assign your order to the well-suited writer, who has the best skills and experience for preparing your specific assignment. You can also request one of these extra features:
    • Choose the Writer’s Samples option – study 3 randomly-provided pages from orders that have been written by the assigned writer.
    • Request a specific writer – choose an academic writer from the dropdown list in the order’s form (optional for returning customers).
    You can be sure that your custom writing order will be accomplished by one of our 400+ professional academic writers. They all pass a series of tests to prove their writing prowess and hold the reputation of being the most professional in the industry. Want to make sure writer’s skills match your needs? Get more details on how to choose the appropriate author.
  • How can I be sure your writing service is not a scam?

    We understand that a shade of mistrust has covered the paper writing industry, and we want to convince you of our loyalty. Apart from high-quality writing services, we offer:
    • The chances of students to boost writing skills in a quick and effective way.
    • The opportunity to manage studies and free time in an enjoyable manner.
    • The possibilities to improve overall academic performance.
    Our custom writing company has been working for more than 12 years and always puts quality and clients’ needs first. Our operations are legally documented, we are easily accessible online and offline,
  • Is it legal to use your professional writing service?

    Yes. Custom writing help is not prohibited by any university or college. It’s a 100% legal way of getting professional assistance with paper writing. Hiring writers from an essay writing company is in many ways similar to consulting a tutor – we help you solve the writing issues at hand.
  • How does your service work?

    Our custom writing service is a reliable solution on your academic journey that will always help you if your deadline is too tight. You fill in the order form with your basic requirements for a paper: your academic level, paper type and format, the number of pages and sources, discipline, and deadline. Then, you describe the specific details of the paper you need: add the topic, write or paste the instructions, and attach files to be used, if you have them. After that, an online customer support representative chooses the best writer that specializes in your discipline and assigns him or her to complete the paper according to your requirements. When the paper is ready, we check it for plagiarism and send it to you. If you want to change something, you can request a free revision.
See full FAQ

Take your studies to the next level with our experienced specialists

Live ChatWhatsApp