I have two char array variables:
char* key set to "foo"
and char* test set to "bar"
When I attempt a strcmp(key, test), my c program seg faults.
What's going on here?
I have two char array variables:
char* key set to "foo"
and char* test set to "bar"
When I attempt a strcmp(key, test), my c program seg faults.
What's going on here?
My guess is you didn't actually do
char *key = "foo";
But instead you either
- forgot to allocate any space for your pointers
- forgot to append a \0 when constructing your strings, one character at a time.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.