0Pricing
C Academy · Lesson

strlen, strcpy, strcat

Core string functions.

Strings in C

In C, a string is just an array of char that ends with a special null terminator character '\0'.

The functions in <string.h> rely on this terminator to know where a string ends. Without it, they read past the end of your array.

#include <stdio.h>

int main(void) {
    char name[] = "Alice";
    printf("%s\n", name);
    printf("Bytes used: %lu\n", sizeof(name));
    return 0;
}

Including string.h

To use string functions you must include the header:

  • #include <string.h>

This gives you strlen, strcpy, strcat, strcmp and more.

#include <stdio.h>
#include <string.h>

int main(void) {
    char greeting[] = "Hello";
    printf("Length is %lu\n", strlen(greeting));
    return 0;
}

All lessons in this course

  1. strlen, strcpy, strcat
  2. strcmp and Comparison
  3. strtok and Tokenizing
  4. memcpy and memset
← Back to C Academy