fgets Questions

5

Solved

I have a text file text.txt that reads (for simplicity purposes) this is line one this is line two this is line three Again for simplicity's sake, I am just trying to set the first character in ...
Robb asked 2/7, 2015 at 14:58

2

Solved

Does the fgets() function move the file pointer automatically to the position till the parameter of the size mentioned by me? for example: the content of the file p.txt is " I am a good boy &q...
Conscious asked 5/5, 2017 at 16:36

5

Solved

I'm trying to read a return delimited file. full of phrases. I'm trying to put each phrase into a string. The problem is that when I try to read the file with fscanf(file,"%50s\n",string); the...
Elation asked 27/4, 2010 at 3:52

4

Solved

The problem with this code is that it does not actually print anything after the user enters in some text in the command line. The purpose of the code is to accept the number of lines the user wi...
Hodge asked 7/4, 2017 at 0:49

3

Solved

what is the correct way to read a text file until EOF using fgets in C? Now I have this (simplified): char line[100 + 1]; while (fgets(line, sizeof(line), tsin) != NULL) { // tsin is FILE* input ...
Poliard asked 16/8, 2016 at 13:42

3

Solved

Supposed to swap every two lines in a file until just one line remains or all lines are exhausted. I don't want to use another file in doing so. Here's my code: #include <stdio.h> int main...
Cook asked 4/2, 2017 at 22:59

3

Solved

In unit testing a function containing fgets(), came across an unexpected result when the buffer size n < 2. Obviously such a buffer size is foolish, but the test is exploring corner cases. Simpl...
Formyl asked 30/4, 2014 at 12:51

2

Solved

Hi i am pretty new to socket programming and I've written a simple client/server system to send data over a socket. I've gotten it working so that I can send a string to the server and receive a re...
Ligulate asked 29/3, 2014 at 2:26

3

Solved

I am trying to read in a string that may or may not include spaces ex. "hello world". By doing the following with a number select menu that is inputted by the user. This is just a small replica of ...
Stipend asked 11/11, 2016 at 16:0

3

Solved

I've been testing this struct out and I get warning about using gets. Somebody mentioned to use fgets instead and replace the end with '\0'. Any recommendation how I can change my code to do that? ...
Schnauzer asked 8/10, 2016 at 8:29

2

I'm prompting for a user supplied string using fgets(user_input, input_len, stdin). How can I send, for instance, the byte represented by hex \x04 to the program?
Cathee asked 23/3, 2016 at 17:51

4

Solved

I'm trying to detect the input of fgets from stdin as empty (when I press enter without entering in anything). Here is my program: int main() { char input[1000]; printf("Enter :"); fgets(input,...
Tusker asked 8/11, 2011 at 23:55

4

Solved

Here is my code: <?php $url="http://www.sina.com.cn"; $handle = @fopen($url, "r"); $len=get_headers($url,true); print_r($len); echo $len['Content-Length']."\n"; if ($handle) { while (($b...
Briolette asked 24/12, 2015 at 2:16

2

Solved

I can't work out what's the problem with my code. Here's my code: #include <stdio.h> #include <stdlib.h> #define N 20 typedef struct _dog { char dogName[N],ownerName[N]; int dogA...
Assay asked 27/12, 2015 at 14:16

5

Solved

Does fgets() always terminate the char buffer with \0 even if EOF is already reached? It looks like it does (it certainly does in the implementation presented in the ANSI K&R book), but I thoug...
Nessim asked 2/11, 2009 at 9:27

7

I've been doing a fairly easy program of converting a string of Characters (assuming numbers are entered) to an Integer. After I was done, I noticed some very peculiar "bugs" that I can't answer, ...
Balough asked 21/7, 2010 at 17:54

4

Solved

This is part of a larger program to emulate the cat command in unix. Right now trying to take input and send it to stdout: char in[1000]; int c = 0; while ((c = getchar()) != EOF) { fgets(in,10...
Wershba asked 28/4, 2015 at 11:52

2

Solved

I have started learning C (via Youtube and K&R) some time ago and I am trying to write some programs as practice. Currently I want to create a program that reads words from a file and compares ...
Dusa asked 27/4, 2015 at 15:10

4

The below code runs perfectly with scanf(), but i want to input characters along with white space. I have tried gets() and fgets() (commented below), but its not working (its skipping to next itera...
Cavorelievo asked 15/1, 2014 at 13:7

4

Solved

What is the difference between fgets() and gets()? I am trying break my loop when the user hits just "enter". It's working well with gets(), but I don't want to use gets(). I tried with fgets() an...
Handed asked 8/2, 2015 at 22:18

5

Solved

Problem: I need to be able identify when two whitespaces occur consecutively. I have read the following questions: how to read a string from a \n delimited file how to read scanf with spaces An...
Infusible asked 21/9, 2010 at 22:39

1

Solved

I'm reading streams in PHP, using proc_open and fgets($stdout), trying to get every line as it comes in. Many linux programs (package managers, wget, rsync) just use a CR (carriage return) charact...
Scevo asked 12/1, 2015 at 17:50

2

I'm trying to write an inputted string elsewhere and do not know how to do away with the new line that appears as part of this string that I acquire with stdin and fgets. char buffer[100]; ...
Evocator asked 15/12, 2014 at 18:49

1

Solved

I've tried looking around and I can't seem to find where the error lies. I know it must have something to do with the way I used fgets but I can't figure out for the life of me what it is. I'...
Pensionary asked 11/10, 2014 at 19:11

5

Solved

I have a script that parses large files line by line. When it encounters an error that it can't handle, it stops, notifying us of the last line parsed. Is this really the best / only way to seek t...
Homemaking asked 27/8, 2010 at 22:35

© 2022 - 2024 — McMap. All rights reserved.