Welcome to CS 241!

Lab 2 - Strings

Strings!

Question 1

Another One

string_array + 2 == 0x

Another One

string_array[0] + 5 == 0x

Another One

string_array[2] + 10 == 0x

Question 2 - Memory Moves

What does each of the things look like right now.

Question 3 - Draw that struct

What does this drawing look like?

Lab Time!

What are we going to be doing?

One function

char** camel_caser(const char *input_str);

What does it do

Input: A sequence of space seperated words Output: A camelcased version of that sequence

Example Input: “Do not go gentle into that good night” Example Output: “doNotGoGentleIntoThatGoodNight”

What is this NULL-terminated array?

Maybe we don’t want to pass around the size of the array everywhere. We also know that NULL is not a valid string, this is not true in all cases.

char **ptr = ...;// vs
int *arr = ...;
arr[len] = NULL; //NULL = 0, meaning we have a valid element

Test Driven Development!

Write Tests and then write the actual code to make your tests pass.

Useful Functions

  • strdup: return a string copy.
  • strcpy,strncpy: copy a string to another string.
  • toupper, tolower: return the upper/lower of input character.
  • ispunct,isspace,isalpha: decide whether it is punct/alpha/space.

  • Be carefull of strtok

Questions?

Authors: Steve & Bhuvan