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
6 answers

Why do I get a number when I stream the result of tolower() to std::cout, but not when I use putchar()?

I was trying to write a program which will convert every word(either upper or lower case) in the upper or lower case(depending on which case is max).So here is my program #include #include #include #include using…
mahin hossen
  • 175
  • 9
1
vote
2 answers

printing line number in c using getchar and putchar

is there a way to print out the line number in C while only using putchar and getchar and no arrays? the output should look like this. for example input mink 01: mink 02: jaguar and so on The line number should go from 01 to 50. This is my start…
user8862019
1
vote
2 answers

How to check if stdin == stdout in C

I am building a program that takes user input, manipulates it, and outputs the changes (if any). The guidelines are: Delete all digits if > 2 newlines in a row, print only 2 change cases of letters print 2 spaces for each space print all other…
z.rubi
  • 327
  • 2
  • 15
1
vote
2 answers

What is wrong with this code of file handling in c?

I am trying to write content in a file from terminal. File is creating but content is not written into the file. #include #include #include int main(int argc, char *argv[]) { FILE *fp; …
Shubham D
  • 79
  • 1
  • 7
1
vote
3 answers

Integer promotion with putchar

"The function returns the character written as an unsigned char cast to an int or EOF on error": see Putchar. In order to do practice, I produced this program: #include int main(void){ for(putchar('1'); putchar('2'); putchar('3')) …
Worice
  • 3,847
  • 3
  • 28
  • 49
1
vote
2 answers

Nobody, never checks the return value of putc, fputc, puts, fputs, putchar (and maybe printf) functions. Why?

$ cd glibc-2.23 $ grep -ErI --include='*.c' '= *f?put([cs]|char)\>' |wc -l 1 $ grep -ErI --include='*.c' '[^= ] *f?put([cs]|char)\>' |wc -l 1764 $ man putc ... RETURN VALUE fputc(), putc() and putchar() return the character written as an…
user7076126
1
vote
1 answer

Difference between post and pre decrement a char pointer value in c function putchar

I have the following code in C (I'm using tdm-gcc 4.9.1 and Netbeans 8.0.2): #include #include #include char * pr(char * str); int main(void) { char * x; x = pr("Ho Ho Ho!"); return…
1
vote
3 answers

Why this approach using putchar_unlocked is slower than printf and cout to print strings?

I'm studying manners of speedup my algorithms for programming's contests, using as base the acceleration of input and output processing. I'm currently using the thread-unsafe putchar_unlocked function to print in some evaluations. I've thought that…
648trindade
  • 689
  • 2
  • 5
  • 21
1
vote
1 answer

Charset of putchar in C

I am trying to figure out what character set putchar uses. Seemingly, it cannot print multi-byte characters: putchar('€') //gcc warning: multi-character character constant But when the codepage of the terminal in Windows is set to 1252 (West…
1
vote
1 answer

How can I keep gcc -O2 from optimizing putchar out?

I have an application that uses a custom putchar(); which until now has been working fine. I bumped up the optimization level of the application to -O2, and now my putchar isn't used. I already use -fno-builtin, and based on some googling I added…
Ed.
  • 928
  • 1
  • 10
  • 23
1
vote
4 answers

Copy input from user and put it on screen

I have been going through The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie and am at Character Input and Output, specifically on File Copying. The example in the book #include int main(void) { int c; c =…
John Vearr
  • 13
  • 2
1
vote
1 answer

getchar buffered input, EOF and terminal driver

I'm trying to understand how the terminal driver works in conjunction with getchar. Here are a few sample codes i wrote while reading KandR: Code 1: #include int main(){ int c = getchar(); putchar(c); return 0; } Code 2: …
user720694
  • 2,035
  • 6
  • 35
  • 57
1
vote
2 answers

print a integer in c using putchar only

This is an old practice and I am trying to identify where i went wrong with my code: write a c program to print an integer using putchar only. I know one right way to do it is: void printnumber(int n) { if (n < 0) { putchar('-'); …
user3858
  • 129
  • 2
  • 3
  • 12
1
vote
5 answers

Reading input from getchar

while(1) { if(i == 6) break; temp[i] = getchar(); putchar(temp[i]); i++; } Whenever i had to use getchar in this way, it accepts enter also as one of the input and thus I am restrained to enter only three characters instead…
Mcolorz
  • 145
  • 1
  • 5
  • 20
1
vote
3 answers

how can character type variable hold more than one byte in this program?

I am using Ubuntu 12.04 LTS with gcc. Can anyone tell me, how can this character type variable hold more than one byte? NOTE : This program will echo all characters(more than one) you type. For instance, if u type "thilip", then it will echo as…