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
1
vote
2 answers

Why am I printing garbage with putchar(); in this for loop?

I'm trying to teach myself C, as you've probably heard so many times, and I cannot figure out what I am doing wrong. The point of the exercise I'm doing is to replace tabs with a specified number of spaces. It's supposed to be a mimic of the unix…
1
vote
5 answers

Can putchar() print an integer?

How can I print an integer with the help of putchar() only. i want to do it without using external storage. This question was asked in an interview last year.
akash
  • 1,801
  • 7
  • 24
  • 42
0
votes
4 answers

Putchar, getchar, missing character in while loop

I've got problem with this peace of code, it should change lower case letters into upper case, and turn multiple spaces into one space. So what it does wrong, it somehow cuts off the first letter like when i write "abcdefg" it givess me on the…
mmajewsk
  • 99
  • 11
0
votes
4 answers

Why does this C code have unexpected behavior

I have written the following simple C code, which compiles and runs fine. However it behaves in a way that I don't understand. I type a character, it prints it on the screen. But when I press the return key it prints the whole line. So if I type the…
user485498
0
votes
0 answers

How can I use putchar to print numbers from 0 to 20 (or more)?

am looking on how to print digits for 0 to 20 and more with puchar i tried using putchar('0' + 48) is just printing from 0 to 9, finding it hard to do that is there any help please, i have also tried constructing the questions but it seems heard to…
ben_code
  • 1
  • 1
0
votes
0 answers

What is the difference between these loops?

I am a beginner of C programming. I am learning C by "The C programming language second edition"(by Brain W.Kerninghan and Dennis M.Ritchie) In the book I am stack with the exercise 1-10. "Write a program to copy its input to its output, replacing…
0
votes
0 answers

Why cant I use the 'putchar' subroutine more than once? Using asm x86_64 AT&T

I am trying to gain a better understanding of the 'putchar' subroutine in assembly to make my own printf function. For this specific problem I want to print the first 2 bytes of the string "Hello world" The code i am using is as…
Tonko
  • 1
  • 1
0
votes
1 answer

How is the output 15 here? can someone explain it to me? I didn't really understand the use of putc and stdout

int *z; char *c = "123456789"; z = c; putc(*(z++),stdout); putc(*z, stdout); return 0; The output is 15 thats for certain but how does this happen.
0
votes
1 answer

Why doesn't my program wait for another input?

I've written a small program to practice getting user input using getchar() and outputting it using putchar() in C. What I want my program to do: I want the program to ask the user to enter a char, store it in a char variable, and print it out. And…
0
votes
1 answer

How can I store and print a character input?

I am familiar with storing and printing characters using getchar(); and putchar();. However, when I use it with my entire code, it does not seem to work. In the command window, it will take the character, but not print it. Thus, I have no idea what…
joelcodes
  • 1
  • 1
0
votes
2 answers

Questions regarding getchar and putchar in C (K&R)

so I'm learning C by following the book, 'The C Programming Language 2nd Edition' by Dennis Ritchie and Brian Kernighan. In section 1.5.1 File Copying, the following program is shown: #include /* copy input to output; 1st version…
staticvoid17
  • 90
  • 2
  • 8
0
votes
1 answer

Do getchar() and putchar() read only one character each time they're called or do they read a stream of characters?

There is something vague about the functionality of getchar(), putchar() in while loop for me. In the following program that copies its input to its output: #include main() { int c; c = getchar(); while (c != EOF) { …
user11329352
0
votes
2 answers

Why putchar() and getchar() are accepting more than one character when using while loop..?

Here, I have understood why putchar() is printing only the first character that is 'C' #include main(){ int c; c = getchar(); putchar(c); } output : > Cprograming > C But, When using a while loop the behavior of…
0
votes
1 answer

C getchar() and putchar()

Going through K&R, I'm trying to get my head around C. I want to write a program that prints on the screen the user's previous line, unless the character was "a". int main(){ int c; while((c=getchar())!=EOF){ if(c!='a') …
user485498
0
votes
1 answer

Problem printing out array using putchar function. Getting a punch of symbols as output

#include void print_rev(char *s); int main(void) { char *str; str = "I do not fear computers. I fear the lack of them - Isaac Asimov"; print_rev(str); return (0); } // read array and print it out backwards char by…
redrosesxo
  • 17
  • 3