Tsallaka zuwa abun ciki
Justice Tech School

Strings

A string is an array of char that ends with the null character \0. Use string.h functions: strlen, strcpy, strcat and strcmp. Never copy into a buffer that is too small.

Example
char name[20] = "Ada";
printf("%s has %zu letters\n", name, strlen(name));
strcat(name, " Lovelace");
printf("%s\n", name);
printf("%d\n", strcmp("a", "a") == 0);
char word[] = "C";
printf("%zu\n", sizeof(word));

Result

Ada has 3 letters
Ada Lovelace
1
2

Exercise

Find the length of a string.

strlen()

Quiz Test

Which character ends a C string?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.