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
-1 votes
3 answers
192 views

When I see code for getting input I see scanf() used most of the time. I see some from the link taking-string-input-space-c-3-different-methods and I also see it on this website. Is there something ...
Chill Dog's user avatar
0 votes
0 answers
57 views

I am trying to make the simplest timer program in C. My attempt is as follows: #include <stdio.h> #include <time.h> int main() { char c; time_t start, end; long int day, ...
Vinayak Deshmukh's user avatar
1 vote
2 answers
141 views

I am having a problem with my program getting stuck on waiting for input after using getchar(). I used a loop to clear the buffer and the same functionality appears four times in my program but only ...
Hexe Decima's user avatar
1 vote
1 answer
97 views

i'm currently going through K&R. right now i'm at exercise 1-18: "Write a program to remove trailing blanks and tabs from each line of input, and to delete entirely blank lines.". ...
Roee Zamir's user avatar
3 votes
3 answers
170 views

A number guessing C program; After the 4th iteration which prompts “well, is it 5 then?”, the character \n (enter) still remains in the buffer which then gets read by the first getchar() in the while ...
memory_pimp941'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
3 votes
2 answers
190 views

I'm writing a test application for a console text input library. The idea of that part of the library is to just treat any input as a regular text input, even Ctrl+[letter] combinations. And for the ...
RobinLe's user avatar
  • 41
0 votes
0 answers
32 views

I am new to C language coding, I was trying to learn the various inputs that I can take from the user and display the same but I keep getting a blank in the place of the printf statement that takes ...
Saikat Das's user avatar
2 votes
1 answer
129 views

While developing a line editor in C++, I'm using getch() to capture each key input, and see \r(13 in ASCII) as the Enter key. However, when pasting text that contains multiple lines, the program ...
caozhanhao's user avatar
0 votes
1 answer
128 views

My code is extremely simple, but I figure that's best to figure out what's going on in my program. For some reason, I can't seem to get ungetc() to work properly, nor can I figure out it's purpose. ...
Ratdude's user avatar
  • 93
-1 votes
2 answers
137 views

i am making a counting program, and i want to add a feature that quits the program, but i don't really know how to do it. i have seen examples on how to do it, but all of them are for windows. please ...
Yakov Kotsarenko'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
108 views

#include <stdio.h> int main() { int c; for (int i = 0; i < 10; i++) { c = (getchar() != EOF); printf("%d\n", c); } printf("As we can see, the value of c is ...
Vedant Yadav's user avatar
3 votes
1 answer
100 views

I'm getting crazy with C. I'm programming with JavaScript, Ruby, Python, PHP, Lua, even Java... Recently, I tried to program a simple Read-Eval-Print-Loop in C. And I have a very strange behavior with ...
Xitog's user avatar
  • 119
0 votes
2 answers
104 views

I wrote this code to get familiar with getchar(). I took line while(ch != '\n' && ch != EOF) ch = getchar(); from a book. What is a mystery to me is that in the second while loop using ...
Peter Kirsch's user avatar
0 votes
3 answers
158 views

I am experimenting with the getchar() function. Can someone please explain why every time I finish an input line with a space and then press Enter, the input window skips a line and then I have to ...
Peter Kirsch's user avatar
1 vote
2 answers
137 views

From what I can tell, this program confuses the terminal emulation on both Linux and WSL, on both python 2 and 3. Once the program exits, characters are no longer echoed and normal terminal function ...
Rich T's user avatar
  • 11
1 vote
1 answer
113 views

I have this code: #include <stdio.h> int main(void) { int d=0; d = getchar(); printf("%d\n", d); } Output: ^Z -1 From what I understand there are two things that could be ...
user394334's user avatar
1 vote
0 answers
57 views

What I want to do is find out if scanf can read ctrl+z as EOF? I know that getchar and scanf return EOF when the end of the file is reached. This I have no problem with. What I want to do is have them ...
user394334's user avatar
0 votes
2 answers
99 views

In the following program: #include <stdio.h> int main() { int c; c = getchar(); putchar(c); } Even if If write many characters in the input and press enter, it only prints the ...
talopl's user avatar
  • 188
3 votes
5 answers
174 views

I am not sure about whether I have to cast a character to an unsigned char before being compared to the return of a getc family function. The functions I consider getc family, are getc, fgetc and ...
woodenadmin's user avatar
1 vote
0 answers
42 views

#include<stdio.h> int main(void){ int character; double balance,amount; printf("Enter the balance: "); scanf("%lf",&balance); printf("Enter ...
Hasindu Dahanayake's user avatar
-1 votes
1 answer
97 views

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #define NUM_DAYS_IN_WEEK 7 typedef struct { char *acDayName; int iDate; ...
Swathi A's user avatar
1 vote
1 answer
62 views

The code: #include <stdio.h> #include <stdbool.h> typedef enum{ counting1, counting2, searching, possiblecom, possibleend, } read_state; bool issep(char a){ return (a == ' ' |...
OctoPussy's user avatar
0 votes
1 answer
145 views

When I enter a number from keyboard, while loop goes 2 times, and I didn't understand why it is doing that. I want to run this loop for one time after each entering number. Is there anyone who can ...
mert onur's user avatar
0 votes
2 answers
70 views

A part of the code I'm writing has to read a sequence of integers separated by a space from input into an array. It works fine when I input, for example, 3 numbers, and then press Enter. But if after ...
Nare Avetisyan's user avatar
3 votes
3 answers
217 views

I am working on a simple program in C that asks the user to give an input in a loop until they enter the letter Q when prompted. When I run the program however, it immediately skips the prompt to ...
Ian's user avatar
  • 31
0 votes
1 answer
56 views

I am trying to write a function that reads an input from the terminal using getchar() and stores it in a string and then display it in 2 different formats. The read line should be stored in the ...
Alex's user avatar
  • 1
0 votes
1 answer
76 views

I'm new to programing and trying to learn C on my own. However I've encounetred a problem I don't know how to solve. This is my simple program. Sorry for grammar mistakes english is my second language....
ILoveYouAll's user avatar
0 votes
3 answers
86 views

If i give my program this: abcdefghijklmnopqrstuvwxyz It answered with this?! Invalid command a Invalid command c Invalid command e Invalid command g Invalid command i Invalid command k Invalid ...
Ronja Oksanen's user avatar
0 votes
1 answer
169 views

I'm going through section 1.9 in K&R, I don't understand the use of EOF in the code implemented below #include <stdio.h> #define MAXLINE 1000 /* maximum input line length */ int ...
Hiểu Nam's user avatar
1 vote
2 answers
200 views

I want to run a simple program: #include <stdio.h> #include <stdlib.h> int main(void) { int c; printf("Please enter a letter: "); while ((c = getchar()) !='.') printf(&...
Dante's user avatar
  • 11
0 votes
1 answer
145 views

#include <stdio.h> #include <stdlib.h> int main() { int num=0,ch='9'; while((ch=getchar())!=EOF){ ++num; } printf(&...
Devesh from India's user avatar
-1 votes
2 answers
117 views

When I take user’s name as input and use that information to do another task, the output does not contains first character of the first student name. int main() { // Task1 - Enter student number ...
Dat Tran's user avatar
0 votes
1 answer
54 views

An assignment asks us to create a program in C that asks for user input of only numbers, using getchar() and infinite loop with while(1), that stops after typing a non-numeric character. This is my ...
Tiến Đạt Lê's user avatar
0 votes
0 answers
43 views

I need to read the following format of text: text textEOF Where EOF is a single CTRL+D and the rest are just the characters (\n is important). The only way it does work is by adding another EOF after ...
Purple6's user avatar
  • 19
0 votes
1 answer
109 views

I tried to using getchar() function to pause program when user enters 'm' or 'M'. The main problem is I don't know why I can't use : while (check != 'm' || check != 'M' ); Instead of: while (check != ...
cherriedy's user avatar
0 votes
0 answers
60 views

I have a simple shell program in C that needs to be able to run as a command line and take in input from the user and also take in input from a file piped in as < commands.txt. for the purposes of ...
fifthfiend's user avatar
-2 votes
1 answer
104 views

I'm new to programming, and I try to program a menu in C++. I want it to be in a while loop, breaking when ESC is pressed, but I want the character to be read instantly without having to press Enter. ...
Radek 's user avatar
  • 11
0 votes
1 answer
81 views

I have a problem with, i think, function INPUT. But i can't understand how to fix it [functions code] typedef struct Item { int data; struct Item* next; } Item; typedef struct Queue{ ...
dima fgb's user avatar
0 votes
0 answers
154 views

I have a C program for linux where the user is intended to pipe information into the program (echo "hello\nworld" | cprogram), and then interactively search through that information. This ...
Tjk's user avatar
  • 11
1 vote
1 answer
141 views

I have the following code. int x1, x2; char check[3]; do{ //input should be (x1,x2) successfully_inputed = scanf("(%d,%d%2s", ...
yad0's user avatar
  • 77
0 votes
1 answer
102 views

I need to read a PPM file but I'm limited to only using getchar() but I'm running into trouble ignoring whitespaces. I'm using num=num*10+(ch-48); to read the height and width but don't know how to ...
Kornilios Ioannou's user avatar
0 votes
2 answers
82 views

I'm trying to write a program which task is to get rid of extra whitespace in a text stream. #include <stdio.h> int main() { int c; while( (c = getchar()) != EOF) { if(...
Rodion Iskhakov's user avatar
-1 votes
2 answers
71 views

char ch; int nr=0; printf("\n: "); ch = getchar(); while(ch != 'q' && ch != 'Q'){ ch = tolower(ch); if(ch == 'a' || ch == 'e' || ch == 'o' || ch == 'i' || ch == 'u') ...
Pocsi Nandor-Szilveszter's user avatar
0 votes
1 answer
2k views

Using ESP-IDF and a ESP32S2 microcontroller, I want my program to wait for input using fgets(), then after pressing Enter printing my input using printf(). void app_main(void) { char command[64] = ...
Radiofreak1041's user avatar
1 vote
1 answer
182 views

Currently completing my C homework for the week and i'm messing about with pointers for the first time properly. We are told to create a main function to deal with our readLine function thats premade ...
Ismaeel Ali's user avatar
0 votes
5 answers
1k views

I'm new to the C language and have to write a program that asks the user to type the letter "t" in uppercase or lowercase and then press enter. The program should inform you if you entered ...
Veanty's user avatar
  • 73
1 vote
4 answers
172 views

I'm trying to write a program which gets one or more input lines, and if one line is too long, it gets folded at a maximum number of chars. My approach would be to write the input chars in a first ...
Me- La Ría's user avatar

1
2 3 4 5
19