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
-3
votes
1 answer

why x - x is nothing in putchar() in c language?

In the code below, if I enter 11(1 and 1), the output is:[]1. [] part is not garbage, I just used the symbols("[]") to express the empty output. Therefore the real output is just 1 with one empty space if front of 1. int main(void) { int x =…
Tom_the_cat
  • 159
  • 12
-3
votes
2 answers

Print out 2 digit numbers using only one integer and putchar

I have to print out 2 digit numbers (00, 01, 02, 03,... ,10, 11,..99) i.e. from 00 to 99 using only one integer and function putchar(). In ASCII table, these are signs from 0x30 (0) to 0x39(9). Also i may only use stdio.h library. Output…
Totenkoph93
  • 43
  • 1
  • 9
-3
votes
4 answers

Please explain this code involving getchar and putter

I attached a picture of a piece of c code that I don't completely understand. I know that getchar returns the next character from standard output and that putchar puts the character on the standard output, but i don't fully understand what the EOF…
-3
votes
2 answers

Multi character constant warning for escaped \t

If I write putchar('\\t'); while trying to print "\t" instead of an actual tab, I get the multi character constant warning. On the other hand, if I write putchar('\\'); I get no warning. Upon looking in the ASCII table, there is no character '\\',…
Sahand
  • 7,980
  • 23
  • 69
  • 137
-3
votes
1 answer

confused about putchar result in C

I have a question regarding the putchar function in C. While I was studying, I stumbled upon the following statement: printf("%c\n",putchar('A'+1)+2); When I compile and execute the programme, the result is BD. I undestand that when we type…
user6843415
-4
votes
1 answer

not able to understand the role of getchar and putchar here

#include #include int main() { int c; c = getchar(); while (c != EOF) { putchar(c); } return 0; } when I compile and give input ABC and then press enter, the never ending loop starts like…
secret
  • 1
  • 1
-4
votes
1 answer

Why is putchar() printing out the char with the "%" symbol?

I have the code: #include int main(void) { int c; c = getchar(); putchar(c); return 0; } and after compiling and running, when I input k for example, it prints out k%. Why is it printing out %? Edit: I tested a few things…
hwkd
  • 2,411
  • 3
  • 18
  • 27
-5
votes
3 answers

How to print a symbol `n` times using a `for` loop, in C?

Is it possible to print '#' n times using a for loop in C? I am used to print(n * '#') in Python. Is there an equivalent for that in C? for(i=0; i < h; i++) { printf("%s\n", i * h); }
-5
votes
2 answers

Possible output of the following program fragment?

for(i=getchar();; i=getchar()) if(i=='x') break; else putchar(i); Answer is : mi Can someone explain this piece of code ?(MCQ Question)
Abdul
  • 69
  • 3
-6
votes
1 answer

why the program is not terminating in gcc?

Why the program listed below is not terminating. I am using gcc compiler in linux. #include int main(void) { int c; printf("Enter characters: "); while((c = getchar()) != EOF) putchar(c); return 0; }
1 2 3
11
12