Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
36 views

09-Unformatted Output Functions

The document discusses various unformatted output functions in C programming including putchar(), putch(), and puts(). It provides the general form, examples, and explanations of how each function works. putchar() and putch() are used to output a single character while puts() outputs a string and appends a newline. Sample programs demonstrate how to use these functions to output characters and strings and convert character cases.

Uploaded by

Devotional Songs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

09-Unformatted Output Functions

The document discusses various unformatted output functions in C programming including putchar(), putch(), and puts(). It provides the general form, examples, and explanations of how each function works. putchar() and putch() are used to output a single character while puts() outputs a string and appends a newline. Sample programs demonstrate how to use these functions to output characters and strings and convert character cases.

Uploaded by

Devotional Songs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Programming Logic

Unformatted
Output
Functions
B.Bhuvaneswaran, AP (SG) / CSE
9791519152
bhuvaneswaran@rajalakshmi.edu.in
putchar() Function
 Writing a single character can be done by using the function
putchar().
 The character being transmitted will normally be expressed as an
argument to the function enclosed in parenthesis following the
word putchar.

Unformatted Output Functions Rajalakshmi Engineering College 2


General Form
 putchar(variable_name);
 where the variable_name is a type char variable containing a
character.
 This statement displayed the character contained in the
variable_name at the terminal.

Unformatted Output Functions Rajalakshmi Engineering College 3


Examples and Explanations
 Example
gender = 'F';
putchar(gender);
 Explanation
• will displays the character F on the screen.
 Example
putchar('\n');
 Explanation
• would cause the cursor on the screen to move to the beginning of the next
line.

Unformatted Output Functions Rajalakshmi Engineering College 4


Program
/* Program to convert a character case - CCPUTCHAR.C */

#include <stdio.h>
#include <ctype.h>

int main()
{
char ch;
printf("Enter an alphabet : ");
ch = getchar();
if(isupper(ch))
putchar(tolower(ch));
else
putchar(toupper(ch));
return 0;
}

Unformatted Output Functions Rajalakshmi Engineering College 5


Output
Enter an alphabet : b
B

Enter an alphabet : B
b

Unformatted Output Functions Rajalakshmi Engineering College 6


putch() Function
 putch() function outputs the character to the current text window.
 It is a text-mode function that performs direct video output to the
console. putch() function does not translate linefeed characters
(\n) into carriage-return / linefeed pairs.

Unformatted Output Functions Rajalakshmi Engineering College 7


General Form
 putch(variable_name);
 where the variable_name is a type char variable containing a
character.
 This statement displayed the character contained in the
variable_name at the terminal.

Unformatted Output Functions Rajalakshmi Engineering College 8


Example and Explanation
 Example
gender = 'F';
putch(gender);
 Explanation
• will displays the character F on the screen.

Unformatted Output Functions Rajalakshmi Engineering College 9


Program
/* Program to convert a character case - CCPUTCH.C */

#include <stdio.h>
#include <ctype.h>
#include <conio.h>

int main()
{
char ch;
printf("Enter an alphabet : ");
ch = getchar();
if(isupper(ch))
putch(tolower(ch));
else
putch(toupper(ch));
return 0;
}

Unformatted Output Functions Rajalakshmi Engineering College 10


Output
Enter an alphabet : b
B

Enter an alphabet : B
b

Unformatted Output Functions Rajalakshmi Engineering College 11


puts() Function
 The puts() function is used to write only one string at a time to the
standard output device (usually the screen) and appends a new
line character.
 The puts() function accepts only a single argument.

Unformatted Output Functions Rajalakshmi Engineering College 12


General Form
 puts(variable_name);
or
 puts("string");
 where the variable_name within the function must be a data item
which represents a string or a character array.
 The string displayed by the puts() function may contain certain
white space characters (spaces, tabs).

Unformatted Output Functions Rajalakshmi Engineering College 13


Example and Explanation
 Example
char empname[] = "Arun";
puts(empname);
 Explanation
• will displays the string Arun on the screen.

Unformatted Output Functions Rajalakshmi Engineering College 14


Program
/* Program to read a line of text and print using puts() - RLTPUTS.C */

#include <stdio.h>

int main()
{
char text[80];
printf("Enter the text. Press ENTER at the end :\n");
gets(text);
puts(text);
return 0;
}

Unformatted Output Functions Rajalakshmi Engineering College 15


Output
Enter the text. Press ENTER at the end :
Welcome to C Programming
Welcome to C Programming

Unformatted Output Functions Rajalakshmi Engineering College 16


Thank You

You might also like