All Questions
101 questions
3
votes
5
answers
141
views
getting a stream of -1 when I pass EOF in an infinite getchar printf loop
I have just started the K&R book. It introduces a loop using getchar() and putchar() to copy characters from input to output until EOF is reached:
main()
{
int c;
while ((c = getchar()) !=...
0
votes
0
answers
61
views
Why does my printf function not work? Is my while loop not ending? [duplicate]
I am just trying to copy and paste the text input. After which the code must show done.
#include <stdio.h>
/*code to copy all input characters and paste it one by one*/
int main()
{
int c;
...
-3
votes
1
answer
55
views
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;
...
0
votes
1
answer
54
views
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, ...
0
votes
1
answer
1k
views
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 ...
0
votes
2
answers
463
views
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 <...
0
votes
1
answer
505
views
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 <stdio.h>
main()
{
int ...
1
vote
3
answers
273
views
Unexpected input when using getchar(), and unexpected output using putchar()
I am new to c and understand very little of it however as far as i understand it this code should either print the character i enter (it should print it twice), or print the number representation of ...
0
votes
2
answers
238
views
Why putchar() and getchar() are accepting more than one character when using while loop..? [duplicate]
Here, I have understood why putchar() is printing only the first character that is 'C'
#include <stdio.h>
main(){
int c;
c = getchar();
putchar(c);
}
output : > Cprograming
...
2
votes
3
answers
4k
views
puts(), gets(), getchar(), putchar() function simultaneously use in the program
I have a confusion related to using puts(), gets(), putchar() and getchar() simultaneously use in the code.
When I have run the below code, it is doing all steps:
taking the input, printing the output,...
1
vote
5
answers
1k
views
How to truncate characters over a certain length in C?
I'm working on a C program that takes in an input of lines of text, and return it by printing only 40 characters each.
So far, I have this code:
#include <stdio.h>
#include <stdlib.h>
int ...
0
votes
1
answer
84
views
What are the numbers associated with printing getchar()?
Code:
int main(void) {
int c;
c = getchar();
while (c != EOF) {
putchar(c);
c = getchar();
printf("%d", c);
}
}
I enter a character and that ...
1
vote
2
answers
83
views
C Simple Code Involving getchar() and putchar() Unexpected Output
As I was following an example from a book,
#include <stdio.h>
main()
{
int c;
c = getchar();
while (c != EOF) {
putchar(c)
c = ...
-1
votes
2
answers
466
views
Replace each string of one or more blanks with a single blank
This was already asked, but I made my own program and I don't know why it doesn't work.
int c;
char blank;
while ((c = getchar()) != EOF) {
if (c == ' ') {
putchar(c);
while ((c = ...
1
vote
3
answers
312
views
putchar() output is a question mark instead entered input stream
I'm trying to output an input stream with alphabet characters in a do-while loop and when
the user does EOF(ctrl+d) the loop stops and the output should be the input stream, but the output is just a ...