Skip to main content
Filter by
Sorted by
Tagged with
1 vote
0 answers
73 views

I'm learning C and wrote a simple program in CLion that echoes '1' for every character read until EOF. However, the actual output doesn't match expectations. Code: #include <stdio.h> int main() ...
joyappre's user avatar
4 votes
5 answers
171 views

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()) !=...
saberton's user avatar
0 votes
2 answers
139 views

#include <stdio.h> int main(){ int c; while((c = getchar()) != EOF)){ putchar(c); } } This is the code from R&K's first charpter. I am confused by the behavior of putchar(): ...
Shadow_Guo's user avatar
0 votes
0 answers
66 views

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; ...
Suresh Karthik's user avatar
-1 votes
1 answer
902 views

currently I am working on C project and i faced the following error - 8-print_base16.c:11: WARNING: suspect code indent for conditional statements (8, 15) related with Betty coding style. This issue ...
Shukufa Bayramzada's user avatar
1 vote
1 answer
146 views

I am trying to print numbers using the putchar() function. Here's my code below: int main(void) { int x = 0; for (; x <= 9; x++) { putchar(x + '0'); } } _putchar('\n'...
SJP's user avatar
  • 31
0 votes
0 answers
120 views

am looking on how to print digits for 0 to 20 and more with puchar i tried using putchar('0' + 48) is just printing from 0 to 9, finding it hard to do that is there any help please, i have also tried ...
ben_code's user avatar
0 votes
1 answer
82 views

I am a beginner of C programming. I am learning C by "The C programming language second edition"(by Brain W.Kerninghan and Dennis M.Ritchie) In the book I am stack with the exercise 1-10. &...
satoru kurita's user avatar
2 votes
5 answers
383 views

Why does putchar outputs '1' for putchar(1+'0') but not '10' but when only a character argument is passed, like putchar('0'), it outputs it. With putchar(1+'0'), I expected an output of 10.
ElormCodes1's user avatar
4 votes
2 answers
4k views

Okay so, I'm pretty new to C. I've been trying to figure out what exactly is the difference between putch() and putchar()? I tried googling my answers but all I got was the same copy-pasted-like ...
why's user avatar
  • 47
0 votes
1 answer
66 views

int *z; char *c = "123456789"; z = c; putc(*(z++),stdout); putc(*z, stdout); return 0; The output is 15 thats for certain but how does this happen.
Eren Acar's user avatar
-3 votes
1 answer
59 views

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; ...
user avatar
-3 votes
1 answer
312 views

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 ...
koil's user avatar
  • 49
0 votes
1 answer
67 views

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, ...
sungenchuang7's user avatar
1 vote
2 answers
200 views

I'm trying to print line numbers in the beginning of the lines without using fgets() yes, it prints line number well when I input multiple files but I want to get result like this. Can you guys help ...
dreamingsoftwareegineer's user avatar
0 votes
1 answer
1k views

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 ...
joelcodes's user avatar
0 votes
2 answers
508 views

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 <...
staticvoid17's user avatar
0 votes
1 answer
526 views

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 ...
user avatar
1 vote
3 answers
287 views

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 ...
Newbie's user avatar
  • 31
0 votes
2 answers
265 views

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 ...
Pradaksh Prarthan's user avatar
2 votes
5 answers
2k views

I have recently started learning C, and I made this small piece of code, but it's not really working the way I wanted: #include <stdio.h> #include <string.h> int main() { int i; ...
Meg's user avatar
  • 29
2 votes
3 answers
4k views

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,...
Priyanka's user avatar
0 votes
1 answer
458 views

#include <stdio.h> void print_rev(char *s); int main(void) { char *str; str = "I do not fear computers. I fear the lack of them - Isaac Asimov"; print_rev(str); ...
redrosesxo's user avatar
1 vote
5 answers
1k views

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 ...
user avatar
0 votes
1 answer
86 views

Code: int main(void) { int c; c = getchar(); while (c != EOF) { putchar(c); c = getchar(); printf("%d", c); } } I enter a character and that ...
Yohora Pancake's user avatar
1 vote
2 answers
97 views

As I was following an example from a book, #include <stdio.h> main() { int c; c = getchar(); while (c != EOF) { putchar(c) c = ...
raincouver's user avatar
-1 votes
2 answers
477 views

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 = ...
MisticniCofi's user avatar
1 vote
3 answers
316 views

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 ...
phos's user avatar
  • 39
0 votes
1 answer
124 views

I do not understand why excessive white space is being written to stdout when I run this program. int main(int argc, char **argv) { argv++; for (int i = 0; i < argc - 1; i++) { ...
Ben Jenney's user avatar
-5 votes
3 answers
3k views

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); }
fedi ben othmen's user avatar
2 votes
1 answer
89 views

In the piece of code given below. Whenever I am inputing a set of characters with a ctrl+z at the end, which should mark EOF for getchar(). It is printing all the characters along with another ...
Anagh Basak's user avatar
0 votes
1 answer
658 views

I am learning C form the book, 'The C programming language'. In that when it was introducing putchar() function using the code as follows: #include<stdio.h> /* program to copy its input to its ...
Singh's user avatar
  • 229
-1 votes
1 answer
231 views

I am compiling and running this code: // hello, world!, without printf #include <stdio.h> #include <string.h> char a[7] = "hello, "; char b[7] = "world!\n"; void ...
Matthew Grimm's user avatar
1 vote
1 answer
303 views

Rewrite the program to distinguish EOF from error for the Getchar () function. In other words, getchar () returns both during the error and at the end of the EOF file, you need to distinguish this, ...
Qualcomm's user avatar
1 vote
1 answer
457 views

Anywhere in the C language, without any libraries, there is no way to print text to the console. printf() could just use language functionality to format a string, and then puts() it, which could work ...
user avatar
0 votes
0 answers
362 views

First of all, this is not a problem nor a bug. I just wanted to know how string input from stdin is handled in getchar(). Also, is the same method used for putchar() but just in reverse? These two ...
EpycZen's user avatar
  • 53
0 votes
2 answers
854 views

I'm writing a Windows console mode C program using Visual Studio 2019 community. I want each backspace seen in the input stream to be printed as the literal string "\b" in the output. How do you ...
user avatar
0 votes
1 answer
77 views

My code reads a textfile or input from the terminal and prints out the message but with each word on a new line the code below works with the exception of double or more spaces. Because I use the ...
martinlikespies's user avatar
-6 votes
1 answer
265 views

Why the program listed below is not terminating. I am using gcc compiler in linux. #include <stdio.h> int main(void) { int c; printf("Enter characters: "); while((c = getchar()) !...
abhishek 's user avatar
1 vote
2 answers
124 views

looking for exercise 1-9 from the K&R book (Copy input to output. Replace each string of multiple spaces with one single space) I found this code on this site. #include <stdio.h> main() { ...
user avatar
1 vote
3 answers
235 views

I am having trouble understanding what getchar() != ' ' and getchar() = ' ' are doing in my code. Why do there need to be opposites. The user may input extra spaces between the first name and last, ...
Nick's user avatar
  • 25
-1 votes
2 answers
44 views

I have been experimenting with getchar(), putchar() and have been trying to use EOF. Below is the snippet of code I have been experimenting with. #include <stdio.h> int main(void) { int c; ...
Swarnim Khosla's user avatar
0 votes
2 answers
639 views

I am trying to create a program that removes the vowels from a sentence. However, my program keeps failing because it keeps printing zero byte in the string. Would anyone be able to show me where I am ...
learningcomputerscience's user avatar
0 votes
2 answers
235 views

Does anybody know what the 1u does in this function? The following function takes an integer and prints out its bits. The line I am trying to figure out is the putchar line. I see it takes an ...
sethlearn's user avatar
1 vote
1 answer
53 views

According to the operation entered from the keyboard, I want to do 5 operations with the switch structure, but gives an error. I tried also getchar & putchar functions... int main() { ...
Emre's user avatar
  • 35
1 vote
2 answers
230 views

So like what the title suggest i have tried to use putchar() to print a result of a not equal to test != but the output i got is a question mark. Here is the code: #include <stdio.h> main() { ...
mrnamya98's user avatar
0 votes
1 answer
798 views

When i try the loop, i find some doubts. When i press "Enter" first time, it prints two blank lines, at the second time, it prints two more blank lines and execution following statement. When i press "...
Absolutelyrun's user avatar
1 vote
1 answer
625 views

Compiling with Clang/GCC and running on Linux: When running the following code I encountered what was to me unanticipated behavior: when entering a single character ("X") I will be prompted to enter ...
NewStack's user avatar
0 votes
2 answers
87 views

Isn't the input and output number of characters be the same? int ch; while(ch != '\n') { ch = getchar(); putchar('K'); }
lazy_beginner's user avatar
-3 votes
2 answers
157 views

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 ...
Saumyojit Das's user avatar