Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C
  • C Basics
  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Arrays
  • C Strings
  • C Pointers
  • C Preprocessors
  • C File Handling
  • C Programs
  • C Cheatsheet
  • C Interview Questions
  • C MCQ
  • C++
Open In App
Next Article:
C Program to Find the Length of a String
Next article icon

C Program To Find Initials of a Name

Last Updated : 04 Jul, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Here, we will see how to find the initials of a name using a C program. Below are the examples:

Input: Geeks for Geeks
Output: G F G
We take the first letter of all
words and print in capital letter.

Input: Jude Law
Output: J L

Approach:

  1. Print the first character in the capital. 
  2. Traverse the rest of the string and print every character after space in capital letters.

Below is the C program to print the initials of a name:

C
// C program to print initials // of a name # include <stdio.h>  # include <string.h> # include <ctype.h>  // Function declaration void getInitials(char* name);  // Driver code int main(void) {         // Declare an character array for      // entering names assuming the      // name doesn't exceed 31 characters     char name[50] = "Geeks for Geeks";          printf("Your initials are: ");          // getInitials function prints      // the initials of the given name     getInitials(name);       }  void getInitials(char* name) {          int i = 0;           if(strlen(name) > 0 &&          isalpha(name[0]))        printf("%c ", toupper(name[0]));           while(name[i] != '\0')      {        if(isspace(name[i]) != 0)        {          while(isspace(name[i]) &&                 i <= strlen(name))          {            i++ ;                       }          printf("%c ", toupper(name[i]));        }        i++;      }   printf("\n"); } 

Output
Your initials are: G F G 

Time Complexity: O(n), where n is the length of the string.

Auxiliary Space: O(1), as constant extra space is used.


Next Article
C Program to Find the Length of a String

O

okaysaoyw
Improve
Article Tags :
  • C Programs
  • C Language

Similar Reads

  • C Program to Find the Length of a String
    The length of a string is the number of characters in it without including the null character (‘\0’). In this article, we will learn how to find the length of a string in C. The easiest way to find the string length is by using strlen() function from the C strings library. Let's take a look at an ex
    2 min read
  • C Program to Check if String is Pangram
    Given a string Str. The task is to check if it is Pangram or not.  A pangram is a sentence containing every letter in the English Alphabet. Examples:  Input: "The quick brown fox jumps over the lazy dog" Output: is a Pangram Explanation: Contains all the characters from ‘a’ to ‘z’]  Input: "The quic
    3 min read
  • C program to print name pattern
    The printing of patterns is the most common and interesting problem. This C program prompts users to input their names and transform each letter of the name into a visually appealing big star pattern. For Example, Input: NAME Output: * * **** * * ****** ** * * * ** ** * * * * ****** * ** * **** * **
    5 min read
  • Lex program to search a word in a file
    Problem: Write a Lex program to search a word in a file. Explanation: FLEX (Fast Lexical Analyzer Generator) is a tool/computer program for generating lexical analyzers (scanners or lexers) written by Vern Paxson in C around 1987. Lex reads an input stream specifying the lexical analyzer and outputs
    2 min read
  • C Program To Print Your Own Name
    Printing your own name means displaying your name on the computer screen. In this article, we will learn how to print your own name using a C program. Examples Input: name = "Rahul"Output: RahulExplanation: The program prints "Rahul" to the screen. Input: name = "Vikas"Output: VikasExplanation: The
    4 min read
  • C Program to Print the First Letter of Each Word
    In a string that contains multiple words, each word is separated by a whitespace. In this article, we will learn how to print the first letter of each word using a C program. The simplest method to print the first letter of each word is by using a loop. Let’s take a look at an example: [GFGTABS] C #
    3 min read
  • C Program to Determine the Unicode Code Point at a Given Index
    Unicode is the encoding mechanism to assign a unique number to each character. The first 128 characters are assigned as ASCII value means Unicode and ASCII value for the first 128 characters is the same. The first 128 characters contain the English Alphabet, Digits, Special Characters, etc. ASCII va
    3 min read
  • How to Match a Pattern in a String in C?
    Matching a pattern in a string involves searching for a specific sequence of characters within a larger string. In this article, we will learn different methods to efficiently match patterns in a string in C. The most straightforward method to match a string is by using strstr() function. Let’s take
    3 min read
  • C Program for Linear Search
    Linear Search is a sequential searching algorithm in C that is used to find an element in a list. Linear Search compares each element of the list with the key till the element is found or we reach the end of the list. Example Input: arr = {10, 50, 30, 70, 80, 60, 20, 90, 40}, key: 30Output: Key Foun
    4 min read
  • How to Search in Array of Struct in C?
    In C, a struct (short for structure) is a user-defined data type that allows us to combine data items of different kinds. An array of structs is an array in which each element is of struct type. In this article, we will learn how to search for a specific element in an array of structs. Example: Inpu
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences