![]() |
VOOZH | about |
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.
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.
printf("your_name_here")
Rahul
Table of Content
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
Output
Enter Your Name: Rahul
Your Name: RahulThe 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()
Vikas
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()
Robert
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()
Robert
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
Gabriel