Questions tagged [putchar]

Anything related to C or C++ standard library functions `putchar` (C) or `std::putchar` (C++). These functions are used to write a single character to the standard output stream `stdout`.

Anything related to C or C++ standard library functions putchar (defined in <stdio.h> C standard header) or std::putchar (defined in <cstdio> C++ standard header). These functions are used to write a single character to the standard output stream stdout.

See CPPreference.com:

175 questions
4
votes
2 answers

C, K&R Exercise 1-6, stuck, confused

I am a noob teaching myself to program in C using The C Programming Language, Second Edition (by K&R). In Chapter 1 Section 1.5.1 File Copying, the authors touch very briefly on operational precedence when making comparison between values,…
H3G3moKnight
  • 123
  • 1
  • 9
4
votes
4 answers

print multiple lines by getchar and putchar

Im a beginner learning The C Programming language and using Microsoft visual C++ to write and test code. Below program in C from text(section 1.5.1) copy its input to its output through putchar() and getchar(): #include int main(void) { …
user2593692
  • 43
  • 1
  • 4
3
votes
2 answers

What's the difference between putch() and putchar()?

Okay so, I'm pretty new to C. I've been trying to figure out what exactly is the difference between putch() and putchar()? I tried googling my answers but all I got was the same copy-pasted-like message that said: putchar(): This function is used…
why
  • 37
  • 4
3
votes
5 answers

Removing multiple blanks using putchar and getchar in C

Problem: Write a program that receives textual input using getchar() and outputs the string, having removed multiples blanks. Here's how I wrote the pseudo-code: While each input character is received before reaching EOF, do the following: 1)…
Omid
  • 2,617
  • 4
  • 28
  • 43
3
votes
1 answer

Performance of putc and putchar?

I have always thought that calling putc multiple times is faster than puts or printf. To print "hello" for example, in a real program I would always use puts or printf, but now I'm writing a program that generates C code, so I was wondering whether…
user3810155
3
votes
3 answers

Are getchar() and putchar() functions or macros?

I referred to two reliable sources for the information and both seems to have different definitions of the same thing: http://www.cplusplus.com/reference/clibr%E2%80%A6 http://www.ocf.berkeley.edu/~pad/tigcc/doc/html/stdio_fputchar.html The first…
Rüppell's Vulture
  • 3,583
  • 7
  • 35
  • 49
2
votes
2 answers

Converting Decimal Literals to ASCII Equivalent for putchar in C

I am trying to understand why the following statement works: putchar( 1 + '0' ); It seems that the + '0' expression converts the literal to the respective ASCII version (49 in this particular case) that putchar likes to be given. My question was…
Hank
  • 25
  • 2
2
votes
5 answers

Why doesn't putchar(1+'0') output 10?

Why does putchar outputs '1' for putchar(1+'0') but not '10' but when only a character argument is passed, like putchar('0'), it outputs it. With putchar(1+'0'), I expected an output of 10.
2
votes
5 answers

Printing a string of names in different lines

I have recently started learning C, and I made this small piece of code, but it's not really working the way I wanted: #include #include int main() { int i; char a[] = "Bill Sarah Alice"; for (i = 0; a[i] != '\0';…
Meg
  • 29
  • 2
2
votes
3 answers

puts(), gets(), getchar(), putchar() function simultaneously use in the program

I have a confusion related to using puts(), gets(), putchar() and getchar() simultaneously use in the code. When I have run the below code, it is doing all steps: taking the input, printing the output, again taking the input, printing the…
Priyanka
  • 21
  • 4
2
votes
1 answer

I am trying to under eof and getchar ()

In the piece of code given below. Whenever I am inputing a set of characters with a ctrl+z at the end, which should mark EOF for getchar(). It is printing all the characters along with another character at the end which has an ASCII value of 26. I…
Anagh Basak
  • 147
  • 9
2
votes
2 answers

Explanation needed to understand this recursive C program to print a string in reverse

I cannot understand when does the putchar line is being executed and how it's helping to reverse the input lines ? If EOF occurs the return statement gets executed , but what happens after that line ? #include int fun_reverse(); void…
samriddha
  • 35
  • 6
2
votes
6 answers

Why is there an extra "*" in the output of this program?

#include int main () { int c; while ((c = getchar ()) != EOF) { putchar (c); printf ("*"); } return 0; } when I run this program, the output I get is as qwerty …
aambazinga
  • 53
  • 7
2
votes
3 answers

Code for changing case of the entered String in C

#include int main() { int c; while ( (c = getchar()) != EOF ) { if (c >= 65 && c <= 90) c += 32; else if (c >= 97 &&c <= 122) c -= 32; putchar(c); } return 0; } In the…
Siddharth
  • 23
  • 4
2
votes
1 answer

putchar and printf not behaving as expected

I'm working through some of the exercises in K&R. Exercise 1-6 asks for verification that the expression getchar() != EOF is either 0 or 1. I understand why it is, but the code I wrote to prove it didn't work as expected. I wrote the following…
BruceM
  • 319
  • 1
  • 3
  • 8
1
2
3
11 12