Work 1: If you liked it then you should've put a string on it.

posted Sep 27, 2016, 5:57 AM by JonAlf Dyrland-Weaver   [ updated Sep 29, 2016, 8:35 AM ]
This will be due Wednesday 10/5 at 8am

First, acquaint yourself with the basic string functions: strlen, strcpy, strcat, strncat and strncpy. You can look at the man pages for each if you are unclear as to their uses. I encourage you to play around with each so you are comfortable with how to use them. Then write your own versions of the following:
  • Required
    • strlen [ int strlen( char * ) ]
    • strcpy/strncpy (choose one)  [ char * strcpy( char *dest, char *source )  char * strncpy( char *dest, char *source, int n)  ]
    • strcat/strncat (choose one)  [ char * strcat( char *dest, char *source )  char * strncat( char *dest, char *source, int n)  ]
    • strcmp  [ int strcmp( char *s1, char *s2 ) ]
    • strchr  [ char * strchr( char *s, char c ) ]
    • You must test every function you write, you will not get full credit for an untested functions
    • You do not need to write 7 functions, only 5, but you need to write 1 or the "n" versions. 
      • (So if you do strcpy then you have to do strncat)
    • A makefile that includes a run target. Do not automatically call run in the first target.
  • Extra
    • strstr
    • The other strn/str version of the functions you wrote above
  • When you test your functions, you might want to run them alongside the regular ones so you can see if they behave exactly the same way or not.
  • Remember you should call them something other than the regular names (like, mystrlen...). 
Github link
https://github.com/mks65/stringy.git

Here's an example of what your code might look like when run:
Before applying functions:
s1 = Hello, length = 5
s2 = , length = 0

Testing regular functions:
Copy s1 to s2: s2 = Hello, length = 5
Cat "Man" to s2: s2 = HelloMan, length = 8
s1 = Hello, length = 5

Testing "n" functions:
s2 = this is l, length = 9
s2 = Hello, length = 5
s2 = Hello123, length = 8

Testing strcmp:
compare ab to abc: -99
compare abc to ab: 99
compare abc to abc: 0

Testing strchr: 
Looking for 1 in Hello123: [1] 
Looking for 0 in Hello123: []

Testing strstr: 
Looking for cde in abcdefg: [cdefg] 
Looking for abe in abcdefg: [(null)]

Comments