You are on page 1of 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