All Questions
111
questions
2
votes
4
answers
113
views
Is there a way to compare multiple strings in C? [ I input them through fgets() ]
int Distance() {
char from[40], to[40];
double val;
double result;
printf("Enter what you want to convert from: ");
fflush(stdin);
fgets(from, 40, stdin);
...
0
votes
2
answers
499
views
How do I use multiple fgets without them interfering with each other?
Here's the basic skeleton of my code:
int getSentence(SearchResults* input){
printf("Enter sentence:");
fgets(input->sentence, 100, stdin);
printf("Enter message ID:&...
0
votes
1
answer
64
views
Finding whether a substring exists in a string using user input from STDIN
I have a simply task that I wish to do here is the workflow
User inputs a string which he/she wishes to search exits in a text file
If string is found, code then prints all the lines in a text file ...
0
votes
0
answers
47
views
Why reading a string from cmd.exe is limited to 256 characters instead of expected 8192 chars
I'am developing a Chess engine in windows 10 in C with W64ming that interfaces a standard GUI (eg Arena Chess) using stdin/stdout according to the UCI protocol.
My problem is that with my program (...
1
vote
1
answer
352
views
How to read from stdin with fgets()?
My professor write a C code about fgets,feof with using stdin.
But I don't understand how it works.
fgets(list, 100, stdin);
while (!feof(stdin))
{
printf("feof!");
fgets(list, ...
1
vote
1
answer
1k
views
How to check if stdin is closed?
I am writing a program which currently gets continuous input from stdin and does something with it until stdin is closed.
fgets(buffer, BUFFERSIZE, stdin);
while(fcntl(fileno(stdin), F_GETFD) != -1 || ...
3
votes
1
answer
75
views
Is there an elegant way to handle the '\n' that gets read by input functions (getchar(), fgets(), scanf()) in C?
I am trying a simple exercise from K&R to append string2 at the end of string1 using pointers. In case of overflow i.e. buffer of string1 can't contain all of string2 I want to prompt the user to ...
0
votes
1
answer
209
views
Simple copying file c program returns corrupted file when using the combination fgets() and fputs(). It does work with getc() and putc()
The following program takes a file attached to stdin and copies it to the file attached to stdout.
If I use fgets() and fputs() the file copied is corrupted but when I use getc() and putc() all is ...
0
votes
1
answer
304
views
c - fgets never return \0 and cause a infinite loop
I tried to make a while loop reading some strings from stdin but it never ends
fgets(string,stringlenght,stdin);
while (string[0] != '\0') {
///some stuff here
fgets(string,stringlenght,...
2
votes
3
answers
1k
views
Input Redirection in C - Using fgets to read from stdin not working
I have an assignment where I need to create a shell in C. One of the specifications is to implement input redirection when the redirection symbol is entered ('<'). Then I am attempting to read the ...
0
votes
1
answer
551
views
Calling fgets in RISC-V assembly on Spike/PK
Update: Writing this out allowed me to spot where I was going wrong, but not why. I am obviously calling fgets in the wrong way, because after five calls I get to the address 0x221000 which is where ...
2
votes
1
answer
755
views
fgets - Take null character into account
When scanning for user input using int scanf(const char *format, ...), I would read one less character than the string's size, because the last character of the string has to be the null character \0.
...
1
vote
0
answers
558
views
C: is `fgets` effective when the buffer size passed to it is smaller than user input?
Suppose the declaration is
char *fgets(char *s, int size, FILE *stream);
Then from the manual, fgets reads in atmost size - 1 bytes from the stream. I have read that fgets is considered safe when ...
1
vote
2
answers
1k
views
I want my program to stop accepting input from console when I type STOP in console C++ Program
I am making a C++ program which accepts input from user (even \n) is required but the program should stop when I type STOP, so can anyone help me out. Earlier I was using getline but that also got ...
0
votes
1
answer
1k
views
Can I read multiple lines from keyboard with fgets?
I am trying to read a few lines from stdin (my keyboard) in C, and I wasn't able to do this.
My input it looks like this:
3
first line
second line
third line
There's my code:
char input[2], s[200];
...