These C string assignments are designed for practice after learning character arrays, the null terminator and common string functions. The original Plus2net exercise inventory is preserved below, with legacy/non-standard functions clearly identified.
strlen().strcpy().,).The original page described this as deleting the string from the nth position. Assigning '\0' at that index actually terminates the string there, so the visible suffix is truncated.
#include <stdio.h>
int main(void) {
size_t position = 12;
char text[] = "welcome to C programming";
if (position < sizeof text) {
text[position] = '\0';
}
printf("%s\n", text);
return 0;
}
#include <stdio.h>
int main(void) {
char text[] = "welcome to C programming";
for (size_t i = 0; text[i] != '\0'; i++) {
printf("i = %zu => %c\n", i, text[i]);
}
return 0;
}
This variation demonstrates a true single-character deletion rather than truncation.
#include <stdio.h>
#include <string.h>
int main(void) {
char text[] = "welcome to C programming";
size_t position = 7;
size_t length = strlen(text);
if (position < length) {
for (size_t i = position; i < length; i++) {
text[i] = text[i + 1];
}
}
printf("%s\n", text);
return 0;
}
"welcome " and "to C" so the result is Welcome to C. Practice with strcat().strncat() so only the required number of characters is appended.strcpy() and concatenation.strcpy().strlen().strrev() is non-standard; also practice the portable replacement shown on that page.strlwr() is non-standard; use the portable alternative for modern C.strupr() is non-standard; use the portable alternative for modern C.'o' in "Welcome to C" with strchr().'o' with strrchr().strcmp().strcmpi() is non-standard; review the portable and POSIX alternatives on the case-insensitive comparison page.strcmp() and case-insensitive comparison.strstr().strset() is non-standard; use the portable replacement on the strset tutorial.Return to the complete C Strings hub for all string functions, search/parsing pages, legacy-function notes and practice links.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.