C has no built-in string type. Strings are just arrays of characters with a special ending.
Direct answer
A C string is a char array that ends with a null terminator ('\0'). Use string.h functions like strlen, strcpy, strcat and strcmp. Always make sure your buffer is large enough, including space for the terminator.
Examples
#include <stdio.h>
#include <string.h>
int main(void) {
char name[20] = "Ada";
printf("%s has %zu letters\n", name, strlen(name));
char copy[20];
strcpy(copy, name);
if (strcmp(name, copy) == 0) {
printf("Same\n");
}
return 0;
}
Safe habits
- Size buffers for the longest text plus one.
- Use
snprintffor formatting into buffers. - Never use
gets. Usefgetsinstead.
char line[100];
fgets(line, sizeof(line), stdin);
Where Teyro fits
Teyro's C for Beginners course turns this into short lessons you can play in a few minutes a day. It has 78 lessons, and you can start free.
The bottom line
Remember the null terminator and watch your buffer sizes.



