Error Handling in C
Ensure robust C programs — learn error detection with return codes, errno, perror/strerror, assertions, memory and file I/O error handling with clear examples.

Master string manipulation in C—learn to create, modify, compare, concatenate, convert, and handle null-terminated char arrays with clear examples.
Strings are a fundamental data type in programming, used to represent sequences of characters. In the C programming language, strings are represented as arrays of characters terminated by a null character ('\0'). This tutorial will cover various string operations, including string input/output, concatenation, comparison, and manipulation.
Table of contents [Show]
In C, strings are sequences of characters stored in an array. The last character of a string is always the null character ('\0'), which marks the end of the string.
Strings can be declared and initialized using the following syntax:
char myString[] = "Hello, World!";
C provides the printf() function for output and scanf() function for input. To print a string, you can use the %s format specifier:
#include
int main() {
char myString[] = "Hello, World!";
printf("String: %s\n", myString);
return 0;
}
To read a string, use the %s format specifier within scanf():
#include
int main() {
char inputString[100];
printf("Enter a string: ");
scanf("%s", inputString);
printf("You entered: %s\n", inputString);
return 0;
}
To find the length of a string, you can use the strlen() function from the string.h library:
#include
#include
int main() {
char myString[] = "Hello, World!";
int length = strlen(myString);
printf("Length of string: %d\n", length);
return 0;
}
String concatenation involves combining two strings into a single string. This can be done using functions like strcat() from the string.h library or by manually iterating through the strings and copying characters.
#include
#include
int main() {
char str1[50] = "Hello, ";
char str2[] = "World!";
strcat(str1, str2);
printf("Concatenated string: %s\n", str1);
return 0;
}
String comparison is performed using functions like strcmp() from the string.h library. It returns 0 if both strings are equal.
#include
#include
int main() {
char str1[] = "apple";
char str2[] = "orange";
int result = strcmp(str1, str2);
if (result == 0) {
printf("Strings are equal.\n");
} else {
printf("Strings are not equal.\n");
}
return 0;
}
To copy one string into another, you can use functions like strcpy() from the string.h library:
#include
#include
int main() {
char source[] = "Copy this.";
char destination[20];
strcpy(destination, source);
printf("Copied string: %s\n", destination);
return 0;
}
C provides various functions for manipulating strings, such as strchr(), strstr(), strtok(), etc. These functions help in searching for characters or substrings within a string, and tokenizing strings into smaller parts.
Ensure robust C programs — learn error detection with return codes, errno, perror/strerror, assertions, memory and file I/O error handling with clear examples.
Unlock flexibility in C—learn how to implement variadic functions using stdarg.h: handling ellipses (...), va_list, va_start, va_arg, va_end, with clear examples.
Unlock the power of C preprocessors — learn directives like #include, #define, macros, conditional compilation, and file inclusion for cleaner, flexible code.
These cookies are essential for the website to function properly.
These cookies help us understand how visitors interact with the website.
These cookies are used to deliver personalized advertisements.


