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
2
votes
7 answers

putchar() function: ambiguous output

Here is a simple code , trying to clear spaces from character array, but output is not like I did expect "YasserMohamed". #include int main() { char x[]="Yasser Mohamed"; char ch; int i=0; while (x[i]!='\n') { …
user6398437
2
votes
1 answer

character array reads 3 inputs instead of 5 in c?

my code is given below #include #include #define size 5 void main(){ int i; char letter[size]; for(i=0;i
user6214813
2
votes
2 answers

K&R book 1.5.1 File Copying

I have looked around the site regarding this K&R example and the answers seem to revolve around 'why is this a type int or what is EOF?' kinda guys. I believe that I understand those. It's the results that I don't understand. I had expected this…
2
votes
1 answer

encode program using getchar from command line argument and putchar to send to decode

So I'm trying to make a encode/decode program. So far I'm stuck in the encode part. I have to be able to get a message from the command line arguments, and encode it using a seeded random number. This number will be given by the user as the first…
2
votes
3 answers

How do you ignore numeric input using getchar and putchar

I am new to C programming. One of my assignment questions is giving me a hard time. Here it is: Write an ANSI-C program that uses getchar() to read characters from the standard input, and uses putchar() to output only the letters, spaces (' ') and…
2
votes
1 answer

Merging fgetc and putchar in while loop

I am writing a simple code to print the content of the file to stdout. When i use this : while((c=fgetc(fp))!=EOF)putchar(c); It works like it should but i wanna to merge putchar and fgetc. So i wrote while(putchar(fgetc(fp))!=EOF); But it…
Chaker
  • 1,197
  • 9
  • 22
2
votes
1 answer

C - Swap chars using getchar and putchar

This is for homework . Must use only getchar and putchar int main(void) { int pch; //first int ch; //second while(1){ pch=getchar(); ch=getchar(); if(((pch>='A' && pch<='Z')) && ((ch>='A' && ch<='Z'))){ putchar(ch); …
2
votes
1 answer

How does an 'enter' input work while running putchar() function in C?

I tested this code: 1 #include 2 3 main() 4 { 5 int c; 6 7 while ((c = getchar()) != EOF) { 8 putchar(c); 9 printf("%d ", c); 10 } 11 printf("%d\n", c); 12 } Question: When I inputted…
microbit
  • 319
  • 3
  • 10
2
votes
2 answers

Can anyone explain what the code putchar('/' //*/ 1) mean

I was doing the exercise of the K&R2. When i was reading the code by Ben Pfaff in this page http://clc-wiki.net/wiki/K%26R2_solutions:Chapter_1:Exercise_23 I coudn't understand what the single code putchar('/' //*/ 1) mean. While in my compiler, it…
NYoung
  • 335
  • 3
  • 12
2
votes
2 answers

I have two questions related to getchar() and putchar()

#include main() { char c; c=getchar(); putchar(c); c=getchar(); putchar(c); c=getchar(); putchar(c); c=getchar(); putchar(c); c=getchar(); putchar(c); } My 1st question is that whenever we use getchar() its create a buffer somewhere…
Vikas Verma
  • 3,626
  • 6
  • 27
  • 40
2
votes
2 answers

Strange display EOF character in the windows console

Recently faced with an interesting interpretation of the EOF character console windows. On some machines running windows 7 code putchar (255) && putchar (-1) is displayed as a space character, and some as 'a' character. The second confuses me. Tell…
iGriffer
  • 250
  • 4
  • 16
2
votes
2 answers

C: printf() and putchar() questions

I was reading K&R book and wanted to test out printf() and putchar() functions in ways that I never tried. I encountered several unexpected events and would like to hear from more experienced programmers why that happens. char c; while((c =…
Jonas Hoffmann
  • 315
  • 7
  • 19
2
votes
1 answer

Outputting a poem in C with each word being on a new line

I have an assignment in a C programming class to output a poem with each word on a new line, using only the functions getchar and putchar. I have the majority of the program written, but I can't figure out how to only have one new line for multiple…
user1681673
  • 368
  • 1
  • 6
  • 28
2
votes
2 answers

getch and putchar not working without return

I have been trying to get getch to work in another program with no success. So I have made the most basic program I can using getch the way I want it to work in the main program. I have researched the need for noecho, cbreak, initscr and nodelay, I…
UNECS
  • 533
  • 1
  • 9
  • 20
1
vote
4 answers

How to compose characters into a single string in memory?

I am working on a school assignment and I need a little bit of help. My question is, how can I compose characters that are read in from a file into a single string of memory. Here is what i have so far. My Code: #include #include…
Cka91405
  • 165
  • 1
  • 8
  • 17
1 2
3
11 12