Questions tagged [fgets]

Anything related to C or C++ standard library functions `fgets` (C) or `std::fgets` (C++). These functions are used to read a sequence of characters from an input stream and to write it into a character buffer as a string.

Anything related to C or C++ standard library functions fgets (defined in <stdio.h> C standard header) or std::fgets (defined in <cstdio> C++ standard header). These functions are used to read a sequence of characters from an input stream and to write it into a character buffer as a string.

See CPPreference.com:

2053 questions
0
votes
2 answers

Wrong string concatenation using strcat

I'm writing a program that reads strings from file, saves them to 'string buffer' and then concatenates those string and writes them to another file. #define _CRT_SECURE_NO_WARNINGS #include #include #include #include…
k1ber
  • 180
  • 1
  • 13
0
votes
2 answers

fgets segmentation fault when reading input from user

here's the offending code using ubuntu char *name; int main(void) { fgets(name, sizeof(name), stdin); } void HUD() { printf("%s ", name); } Here's my problem. I started with scanf("%s", &name) and was getting junk at the end of the string.…
nanthil
  • 65
  • 1
  • 4
  • 11
0
votes
1 answer

fgets() halting without error in Swiftmailer

I'm attempting to generate a test email in Laravel 4.2 (Windows 7, IIS 6.1), and I've encountered a silent termination - it just fails, doesn't return my view, and doesn't return an error or Exception. I've managed to brute force my way through the…
dspitzle
  • 740
  • 2
  • 9
  • 26
0
votes
1 answer

What will cause fgets() to continuously wait for input?

I am trying to put together a program that will ask the user to enter song titles for a set list to be printed in a random order. The program uses fgets() to take in the song titles. It also uses memory allocation to put each song in. It is similar…
Raoul Duke
  • 131
  • 7
  • 24
0
votes
1 answer

Using fgets() in a proper way

We have a project for this semester in embedded systems programming (C). I made a client/server program(Chat program) but my professor said when i am using the fgets it is not resource friendly but i don't know why. Here is my source: if (argc ==…
Gabesz
  • 193
  • 3
  • 14
0
votes
0 answers

Could "fgets" inside a while loop corrupt memory somehow?

edit: SOLVED! thanks to @M OEHM who noticed that I had a pointer to szLine (the code isn't showing here). The trick was to use strcpy to another char* pointer. how did i miss it... :( I've been debugging this problem for quite a good time now, also…
alonbe
  • 73
  • 5
0
votes
0 answers

Reading words from file and storing in tree

I'm trying to read in words from a file and store them in a tree. Dictionary newDictionary(FILE *inf) { assert(inf != NULL); int i; char word[MAX_WORD_SIZE]; Dictionary dict = malloc(sizeof(DictionaryRep)); dict->tree =…
gettingthere
  • 19
  • 1
  • 6
0
votes
2 answers

Find words divided by whitespace

Is it possible to use fgets() to save different words divided by whitespace and then find each word? For example let's say I have this: char words[100]; fgets(words,100,stdin); and then I have to find each word to use it in the rest of my program.…
Harr Tou
  • 41
  • 2
  • 9
0
votes
1 answer

PHP replace line at the top of a text file with fgets

I'd like to use php to open a file and replace just one line that will be near the top. Since it's near the top I don't want to read the whole file into memory. Here is what I've tested but I think I am not understanding how to backspace over the…
emailcooke
  • 271
  • 1
  • 4
  • 17
0
votes
3 answers

Code keeps crashing (Week 4.2 has stopped working

I have a program that has to get the longest sentence from a file. To achieve this, I am putting the first sentence in an array and then comparing future sentences to the currently largest sentence's size. However the act of comparing both array's…
0
votes
1 answer

receiving input using fgets in assembly

I got a problem with reading to a buffer using fgets in assemmbly. I know that the numbers are equal to the ASCII value ATM , and its not the problem. I cant get the real value of the user input. Before using fgets I am required to print the string:…
lolu
  • 370
  • 4
  • 20
0
votes
2 answers

How can I most efficiently read the first n lines of a large text file in php?

So far I'm able to return the entire file, or an empty string. But not the first n lines of a file as expected. echo head('/path/to/my_file.txt',100); // returns '', or in other versions `1\n1\n...` function head($filepath, $lines = 1, $adaptive =…
Ryan
  • 14,682
  • 32
  • 106
  • 179
0
votes
2 answers

Unwanted line break in C

I have created a little script in C which displays text in a Linux console, but I found one problem - the script adds a line break at the end of text. I have no idea why, normally I should get line break after /n. #include #include…
Matt
  • 7
  • 5
0
votes
1 answer

Input values not saved correctly in char arrays

What is wrong about the code? The values are not saved correctly in the arrays. /*Deklaration und Initialisierung*/ float addition1=15, addition2=9, subtrahend1=5, subtrahend2=2; double multiplikation1=9, multiplikation2=21, divident1=10,…
wsdt
  • 95
  • 1
  • 8
0
votes
2 answers

How to break a string, that was read using fgets(), using scanf("%s",..)

I am working on a program that takes a mathematical expression, transforms it to posfix notation and then solves it. First I am checking the expression to see if it is well formed ( Open brackets and parenthesis matches the closing ones ). To do the…
1 2 3
99
100