posted Sep 27, 2018, 11:06 AM by Konstantinovich Samuel   [ updated Sep 27, 2018, 12:29 PM ]

This will be due Monday, 10/1

You will be working with a partner on this assignment,

Please name your repo MKS65C-Str

Please add your partner as a collaborator.

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 (use the function headers I provide, they may differ from the standard headers, but name them differently).
    • 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 ) ]
      • Your version does not need to return the same exact value as the system version, as long as it returns -, + or 0 when it should.
    • 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 of the "n" versions. 
      • (So if you do strcpy then you have to do strncat)
    • A makefile that includes a run and compile target.
    • It should automatically call compile. (place compile first!)
  • Extra
    • strstr [ char * strstr( char *s1, char * s2 ) ]
    • The other strn/str version of the functions you wrote above
  • When you test your functions,  run them alongside the regular ones so you can see if they behave the same way or not.
  • Remember you should call them something other than the regular names. mystrcpy, mystrncpy, mystrstr etc.

Here's an example of what your code might look like when run:
s1: [?
s2: [hello]
s3: [goodbye]

Testing strlen(s2):
[standard]: 5
[mine]: 5

Testing strcpy(s1, s2):
[standard]: [hello]
[mine]: [hello]

Testing strncpy(s1, s3, 3):
[standard]: [goolo]
[mine]: [goolo]

Testing strcat(s1, s3):
[standard]: [goologoodbye]
[mine]: [goologoodbye]

Testing strncat(s1, s2, 3):
[standard]: [goologoodbyehel]
[mine]: [goologoodbyehel]

Testing strchr(s1, 'l'):
[standard]: [0x7fff57d70a13]
[mine]: [0x7fff57d70a13]

Testing strchr(s1, 0):
[standard]: [0x7fff57d70a1f]
[mine]: [0x7fff57d70a1f]

Testing strchr(s1, 'z'):
[standard]: [0x0]
[mine]: [0x0]

Testing strcmp
Comparting ab to abc:
[standard]: [-99]
[mine]: [-99]
Comparting abc to ab:
[standard]: [99]
[mine]: [99]
Comparting abc to abc:
[standard]: [0]
[mine]: [0]