Home » C programs » stdio.h header file functions

puts() and putchar() functions of stdio.h in C

In this article, we are going to learn about the putchar() and puts() function of stdio.h header file in C programming language, and use it put string and characters on console.
Submitted by Abhishek Sharma, on April 12, 2018

The function puts() is used to print strings while putchar() function is used to print character as their names specifies.

These functions are from the stdio.h class doing the jobs related to strings.

Example:

    puts("I AM A STRING");
    Output:
    I AM A STRING

    putchar("a");
    Output:
    a

You can also use printf() which have more options then these two functions.

stdio.h - puts() and putchar() functions Example in C



#include <stdio.h>
#include <string.h>

int main ()
{

	// initializing the variables
	char a[15];
	char b[15];
	char c;

	// coming string in a and b
	strcpy(a, "includehelp");
	strcpy(b, "ihelp");

	// put a and b
	puts(a);
	puts(b);

	// printing characters
	for(c = 'Z' ; c >= 'A' ; c--)
	{
		putchar(c);
	}

	return(0);

}

Output

stdio.h - puts() and putchar()  in c language





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.