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 Print the First Letter of Each Word
Next article icon

C Program To Print Your Own Name

Last Updated : 10 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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: Rahul
Explanation: The program prints “Rahul” to the screen.

Input: name = “Vikas”
Output: Vikas
Explanation: The program prints “Vikas” to the screen.

Print Your Own Name Using printf()

The simplest way to print something is to use the printf() function. You can provide your name in the form of string to printf() function and it will print it on the output screen.

Syntax of printf

printf("your_name_here")

Program to Print Your Own Name Using printf

C
// C Program to Print Your Own Name using printf #include <stdio.h>  int main() {        // Printing your name "Rahul" on the output screen     printf("Rahul");      return 0; } 

Output
Rahul

Table of Content

  • Other Different Ways to Print Your Own Name in C
    • Take Your Name as Input and Then Print It
    • Using puts()
    • Using fputs()
    • Using fprintf()
    • Using Write System Call

Other Different Ways to Print Your Own Name in C

Apart from the printf function, we can also print our name on the screen using other methods provided in C:

Take Your Name as Input and Then Print It

We can use scanf() function to take the name as input from the user and store it in a character array. We can then use printf function to print the name on the screen.

Syntax of scanf()

scanf("%s", charArr);

Program to Print Your Own Name by Taking it as Input

C
// C Program to Print Your Own Name using scanf and printf #include <stdio.h>  int main() {        // Defining string (character array) assuming 100     // characters at max     char name[100];      // Taking input from the user     printf("Enter Your Name: ");     scanf("%s", name);      // Printing your name to the screen     printf("Your Name: %s\n", name);      return 0; } 


Output

Enter Your Name: Rahul Your Name: Rahul

Using puts()

The puts() function is another function that is used to print the given string to the output screen. It is also defined inside the <stdio.h> header file.

Syntax of puts()

puts("name");

Program to Print Your Own Name Using puts()

C
// C Program to Print Your Own Name using puts #include <stdio.h>  int main() {        // Print the name "Vikas" on the output screen     puts("Vikas");      return 0; } 

Output
Vikas 

Using fputs()

The fputs() function is used for file output. We can redirect this function to standard output buffer “stdout” to print your name on the console screen.

Syntax

fputs("name", stdout);

Program to Print Your Own Name Using fputs()

C
// C Program to Print Your Own Name using fputs #include <stdio.h>  int main() {        // Print the name "Robert" on the screen     fputs("Robert", stdout);      return 0; } 

Output
Robert

Using fprintf()

The fprintf() function is used also for file output. It is similar to the printf function, but we need to specify the output buffer in the function which in this case is stdout.

Syntax

fprintf("name", stdout);

Program to Print Your Own Name Using fprintf()

C
// C Program to Print Your Own Name using fprintf #include <stdio.h>  int main() {     // Print the name "Robert" on the screen     fputs("Robert", stdout);      return 0; } 

Output
Robert

Using Write System Call

The write() function performs the write system call to the operating system which is used to write some data to some specific file. We can use this print your name by directly writing it to the output buffer.

Syntax of write()

write(STDOUT_FILENO, "name", strlen("name"));

STDOUT_FILENO is the file descriptor for the stdout buffer. Its value is 1 by standard.

Program to Print Your Own Name Using Write System Call

C
// C Program to Print Your Own Name using write system call #include <unistd.h> #include <string.h>  int main() {        // Define the name string     char name[] = "Gabriel";      // Print the name using the write system call     write(STDOUT_FILENO, name, strlen(name));      return 0; } 

Output
Gabriel


Next Article
C Program to Print the First Letter of Each Word
author
mukulsomukesh
Improve
Article Tags :
  • C Language
  • C Programs
  • C Basic Programs

Similar Reads

  • 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
  • C Program to Print Contents of File
    C language allows users to process the files in its programs. Reading a file is a step-by-step process in which we first have to prepare the file only after which we can start reading. In this article, we will learn how to read and print the contents of a file using C program. The simplest method to
    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
  • Your First C Program
    Like in most of the programming languages, program to write the text "Hello, World!" is treated as the first program to learn in C. This step-by-step guide shows you how to create and run your first C program. Table of Content Setting Up Your EnvironmentCreating a Source Code FileNavigating to the S
    5 min read
  • C Program For Char to Int Conversion
    Write a C program to convert the given numeric character to integer. Example: Input: '3'Output: 3Explanation: The character '3' is converted to the integer 3. Input: '9'Output: 9Explanation: The character '9' is converted to the integer 9. Different Methods to Convert the char to int in CThere are 3
    3 min read
  • How to Write a Command Line Program in C?
    In C, we can provide arguments to a program while running it from the command line interface. These arguments are called command-line arguments. In this article, we will learn how to write a command line program in C. How to Write a Command Line Program in C? Command line arguments are passed to the
    2 min read
  • C Program to Print Continuous Character Pattern
    Here, we will see how to print continuous character patterns using a C program. Below are the examples: Input: rows = 5Output: A B C D E F G H I J K L M N O Input: rows = 3Output: A B C D E F There are 2 ways to print continuous character patterns in C: Using for loop.Using while loop. Let's discuss
    5 min read
  • C Program to Print all digits of a given number
    Given a number N, the task is to write a C program to print all digits of the number N in their original order. Examples: Input: N = 12 Output: 1, 2 Input: N = 1032 Output: 1, 0, 3, 2 Method 1: The simplest way to do is to extract the digits one by one and print it. Extract the last digit of the num
    3 min read
  • C Program to Print Right Half Pyramid Pattern
    The Right Half Pyramid Pattern is a triangular pattern consists of rows where each row contains an increasing number of characters. The number of characters starts from 1 and increases by 1 in each subsequent row. Characters are aligned to the left, resembling a right-angle triangle with its hypoten
    2 min read
  • How to Read Input Until EOF in C?
    In C, reading input until the End of the File (EOF) involves reading input until it reaches the end i.e. end of file. In this article, we will learn various methods through which we can read inputs until EOF in C. Reading Input Until EOF Read Input Until EOF Using getchar()Read Input Until EOF Using
    5 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