📝⚡Beginner
Print First Letter of Each Word
Extract initials
Print the first letter of each word (extract initials) from a string.
Program Code
first_letter_words.c
C
1#include <stdio.h>2#include <ctype.h>34int main() {5 char str[] = "Hello World Programming";6 7 printf("String: %s\n", str);8 printf("First letters: ");9 10 // First character is always first letter11 if (str[0] != ' ') {12 printf("%c", toupper(str[0]));13 }14 15 // Find first letter after each space16 for (int i = 1; str[i]; i++) {17 if (str[i - 1] == ' ' && str[i] != ' ') {18 printf("%c", toupper(str[i]));19 }20 }21 printf("\n");22 23 return 0;24}Output
String: Hello World Programming
First letters: HWP
Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials