程序代写代做代考 CAMEL CASER EXTREME EDGE

CAMEL CASER EXTREME EDGE
CASES






• •
HOW TO WRITE GOOD PROGRAM
Modularize your code
Don’t try to know all and do all
e.g. toupper() should do only to upper things, not i/o Think of all possible cases you might meet
vector_insert(int* vec, int index, int value) what if index > vec_size?
what if vec == NULL





HOW TO WRITE GOOD PROGRAM-CONT’D
Make every unit(function) robust
Make sure each unit is robust before you move on to next one
Test your unit
Test each function at a time
Then test combinations of different operations

CAMEL CASER

• •
• •



char ** camel_caser(const char * input ) for every sentence
make every word camel cased
remove all whites Definition of camel cased
make every letter lower cased if ! ( first word of a sentence)
make it upper cased
return an array of string terminated by NULL


CAMEL CASER

remove_whites()

• do_camle_case()
• for every letter l in str • tolower( l )
• for every word w of a sentence
if ! ( first word of a sentence) toupper( w )L


CAMEL CASER
char ** camel_caser(const char * input )
split_input() -> get array of each sentence without punctuation and terminated by NULL
like [“HI I’m Steve”, “this is a sentence”, NULL] for every sentence
do_camel_case()
• •




HOW TO SPLIT STRING
First count your punctuation -> c
you need a array that can contains (c+1) char*
Use two pointer
one to memorize the last punctuation (old_pos)
move the other one until you meet a new punctuation (new_pos) copy substring
What is the size? update old_pos














USEFUL FUNCTIONS DONEC QUIS NUNC
ispunct(), isspace(), isalpha()
use these instead of things like str[i] == ‘ ‘
char* strncpy(char*dest , const char*src, size_t n); copy a substring of src to dest
char * strdup(const char * s); return a duplicate of s
it is allocated on heap -> can be freed int toupper( int c); int tolower(int c);
return upper cased/lower cased of c




• •
• • •

TEST YOUR CAMEL CASER
Write a function to compare camelCaser’s output with expected output unit_test(char** output, char* expected_output)
pass &= unit_test(camel_output, “hiImSteve”);
Cannot use your implementation in camelCaser_test.c
Test each unit separately
“ “, “ \t” -> test white spaces
“abc” -> not a sentence
“…..” ->what happens if there are only dots
You can use ref to check your output

CAMELCASER_TEST.C
CAMELCASER_MAIN.C
CAMELCASER.C

• •
• • • •
REMINDER
You can only modify camelCaser.c and camelCaser_test.c
Please try reference program yourself if you want to know standard output
Use ispunct(), isspace(), isalpha()
Read specs on course webpage carefully
strlen() does not include null-terminator
#define _GNU_SOURCE_ if you want to use strdup