2,092 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
3
votes
1
answer
135
views
How to make C shell exit immediately on Ctrl+D (EOF) when the buffer contains text?
I am writing a simple shell in C on Linux. My goal is to handle the Ctrl+D (EOF) signal such that if the user types a command (e.g., ls) and presses Ctrl+D, the shell exits immediately without running ...
-3
votes
1
answer
197
views
How does fgets work when reading a file or stdin? [closed]
I am following the Bro Code course of C and there is something I am not fully understanding. This might be a basic question, but I cannot figure out what is going on behind the function fgets.
When ...
-3
votes
2
answers
208
views
Files created with C are displayed with the '\n' character in bash [duplicate]
#include <stdio.h>
#include <string.h>
int main(){
char filename[32], userdata[4096];
printf("type the filename bro: ");
fgets(filename, 32, stdin);
printf(&...
0
votes
1
answer
68
views
fgets don't let me input nothing after printf [duplicate]
typedef struct
{
char name[20];
}NAME_1;
static void ex6() {
NAME_1 name;
fflush(stdin);// clean buffr input
printf("Name: ");
fgets(name.name, 20 , stdin);
printf(&...
0
votes
3
answers
152
views
Is there an better/efficient way to keep asking for user input from STDIN using fgets() in C?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXSIZE 10
int main(int argc, char *argv[]){
char input[MAXSIZE], c, *input_ptr;
input_tag: printf("...
1
vote
1
answer
78
views
String data from fgets is lost when using printf [duplicate]
I am new to C programming, and right now doing my first assignment in a C course.
I have noticed an unusual behavior when using a string in my code.
I am currently writing a simple string encoder, our ...
0
votes
1
answer
98
views
behaviour of scanf vs fgets [duplicate]
Please see the following piece of code in C
printf ("\nEnter the lines (terminate each line with ENTER...\n\n");
for (i = 0; i < lines; i++)
scanf (" %[^\n]", s[i]);
I have ...
1
vote
2
answers
136
views
Check incomplete line in fgets()
To detect it, I've seen the following if condition:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
char line[5];
while(fgets(line, 5, stdin)){
int ...
0
votes
2
answers
211
views
Find space in C
I am learning C and I am looking at some tutorials and I am now learning about while. In the video there was example of asking "what is your name?" and while is used there as a tool that ...
4
votes
2
answers
238
views
Why does fgets() require a maximum size of user input? Is it because it does not have the "restrict to first space" property of scanf()?
This is fgets()'s official prototype:
char *fgets(char *str, int n, FILE *stream);
Why specify the size (n) ? Is it to prevent buffer overflow of some sort? Or is it just a design flaw?
I would think ...
2
votes
3
answers
218
views
Why is the strlen here equal to 25?
Just so I can confirm if what I think is going on is really going on. The following code prints out 25 when I give it the (26 letter) alphabet as an input, is it because fgets always automatically ...
0
votes
0
answers
42
views
unable to take input of strings from user [duplicate]
I have to make an array of structure for cricketers presenting their name, age etc. and take input of each value from user . I am trying to get value of name from the user but my code editor keeps on ...
0
votes
2
answers
75
views
C++: fgets issue in getting command terminal data
I am writing a C++ program for an embedded Linux application for a custom device. Very often, I run Linux terminal commands via popen and pclose. If I need to only check whether the command was ...
-1
votes
2
answers
109
views
Edit: How many char does fgets consider from *stream, when passing to its char *str? [closed]
I have been sitting on this simple fundamental mistake for a while.
How do we avoid strings in the stdin, that are bigger than a defined sizeof(sring). Here sizeof(stdin_passed) > sizeof(word_new)....
1
vote
2
answers
162
views
In C, is input = fgets(input,sizeof(input),*pt) a mistake?
Is it correct that in C programming when we pass the parameters pointer_to_string, sizeof_string and the stream for the fgets() function, we do not have to write back the return of the function to the ...