C Program To Print Your Own Name
Last Updated :
10 Sep, 2024
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;
}
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:
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;
}
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;
}
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;
}
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;
}
Similar Reads
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 Triangle
Here, we will see how to print a triangle using the C program Input: 5 Output: * * * * * * * * * * * * * * * Approach: The approach is very simple. We just execute a nested loop, and only print characters when the inner loop is executed after that just change the line. Example: C/C++ Code // C progr
1 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
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 Concatenate Two Strings Using a Pointer
Concatenating two strings means appending one string at the end of another string. While the standard library provides strcat() for concatenation, this article will demonstrate how to concatenate two strings using pointers. To concatenate two strings using pointers, traverse the first string to its
1 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
C Program to Check for Palindrome String
A string is said to be palindrome if the reverse of the string is the same as the string. In this article, we will learn how to check whether the given string is palindrome or not using C program. The simplest method to check for palindrome string is to reverse the given string and store it in a tem
4 min read
C Hello World Program
The âHello Worldâ program is the first step towards learning any programming language. It is also one of the simplest programs that is used to introduce aspiring programmers to the programming language. It typically outputs the text "Hello, World!" to the console screen. C Program to Print "Hello Wo
1 min read