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

absolute value of difference between 2 chars in ASCII table without "abs" or "if"

this is my code: #include void main() { char a, b; char c; printf("enter 2 chars: "); a = getchar(); b = getchar(); c = a - b; printf("%d",c ); } I'm trying to find the absolute…
Majd Sadi
  • 49
  • 7
-1
votes
1 answer

getch is beeing skipped in a while loop

I have this function, while checks for correct input which need to be between 1-6 but when I call this function it just skips all the getch and all the putchar. What am I doing wrong? int firstNum = 0; int secondNum = 0; int thirdNum =…
-1
votes
2 answers

Why is putchar creating a new line in my marquee program?

Here is my code: #include #include void ignoreRestOfLine(FILE* fp) { int c; while ( (c = fgetc(fp)) != EOF && c != '\n'); } int main( void ) { int num_times, count =0; int length; scanf("%d ", &num_times); …
user5983028
-1
votes
1 answer

Splitting strings and printing the capitalized first characers in C

I am working on a code that takes the string containing the name of someone and prints the initials of that name capitalized, whenever I run my code, I keep getting the initials printed twice, which I don't know how to fix this issue and get the…
-1
votes
2 answers

I am using while loop to enter characters one by one(total number of characters to be entered is unknown). How can I store my characters in an array:

User has to input a string of unknown length(<1000). So here I am using while loop, #define, getchar. What should I do to store the characters simultaneously? #include #define EOL '\n' int main() { int count=0; char c; …
Sunil Kumar
  • 390
  • 1
  • 7
  • 25
-1
votes
3 answers

Using getchar() to store numbers

I have an assignment where I'm supposed to make a simple arithmetic calculator in C that takes an input of a number, an operator, and a second number and performs the operation and outputs it. Sounds pretty simple right? I'm limited to using…
OmriSama
  • 302
  • 5
  • 11
-1
votes
1 answer

C - Read from input stream, tab as spaces

I'm a bit stuck and am hoping that someone can take a quick look to find what I'm doing wrong. I want to have the tabs count as spaces for output and not tabs. In this case, I'm using 3 spaces = 1 tab. I'm assuming that it may be something to do…
user3594736
  • 91
  • 1
  • 2
  • 12
-1
votes
5 answers

Not getting correct variable assignment from getchar in C

I'm writing a simple calculation program, however the only string handling functions I can use are getchar and putchar. Right now I'm just trying to assign the numbers from input to variables, but when I print the variable it's some random number.…
user1681673
  • 368
  • 1
  • 6
  • 28
-2
votes
3 answers

Using putchar() and getchar() to print individual characters

I'm trying to use putchar() and getchar() to read in a string of characters from the user, and then my loop will print each character three times, print a new line, etc etc, until every character in the variable "userInput" has been printed. When I…
A.Coder
  • 51
  • 3
  • 8
-2
votes
4 answers

How are getchar() and putchar() Macros?

From what I understand about macros in C, they are predefined constants that will be used throughout the program with their constant value, so we go ahead and define them to avoid further complications and make the code more readable, so people…
AliMan
  • 155
  • 7
-2
votes
1 answer

Add an integer to a char in C

I'm learning C from the K&R book, I found a suggested solution online to a task in the book.The task and suggested answer can be found here (the last solution on that page) http://clc-wiki.net/wiki/K%26R2_solutions:Chapter_1:Exercise_13 Where there…
blender28
  • 3
  • 2
-2
votes
2 answers

What is the practical use of getchar and putchar?

What are the practical uses of these functions? I mean if we use them using while loop and EOF we get just what we type like if we give input "hello" we will get the output as "hello". So what's the point?
-3
votes
1 answer

Im a beginner to C and getting an error with my code: assignment to char from char * makes integer from pointer without a cast. How could I fix this?

Im trying to write a code that gets vowels from a string and replaces them with a "*" before outputting the changed string using the functions of getchar() and putchar(). char input_char; input_char = getchar(); while(input_char != EOF) { if…
user19746829
-3
votes
1 answer

What's the return type and argument of putchar()

I see that return type of putchar() is int, int putchar(int char) but for(i=65;i<91;i++) putchar(i); gives output ABC...... How?Shouldn't it return int? Plus, it turns out that I can use character in argument too.How?
koil
  • 41
  • 4
-3
votes
2 answers

How does the putchar and whole of the code gets executed?

I want the dry run of the code for the first 3 iterations to understand. THe output of the code is : abcdbcdbcdbcdbc........(infinte times) I know how for loop works and put char also.I did not dry run as i was not understand will the third…
Saumyojit Das
  • 101
  • 1
  • 7
1 2 3
11
12