string.h Functions
strlen, strcpy, strcat, strcmp and strchr work on C strings. Make sure the buffer is big enough.
Example
#include <stdio.h>
#include <string.h>
int main(void) {
char a[20] = "Hello";
strcat(a, " C");
printf("%s %zu %d\n", a, strlen(a), strcmp("a", "b") < 0);
printf("%s\n", strchr(a, 'C'));
return 0;
}Result
Hello C 7 1 C
Exercise
Compare strings.
(a, b)Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.