Introduction to Stringsin C
• • Strings are arrays of characters ending with
'0'
• • Declared as: char str[20] = "Hello";
• • String functions are defined in <string.h>
Best Practices
• •Always allocate enough space for strings
• • Remember the null terminator '0'
• • Prefer fgets() over gets() for input
• • Use strncpy() to avoid buffer overflows
25.
Summary
• • <string.h>provides many useful string
functions
• • Basic: strlen, strcpy, strcat, strcmp, strchr,
strstr
• • Advanced: strtok, strdup, memset, memcpy,
memmove, memcmp, etc.
• • Always handle memory carefully in C