fgets Questions

3

Solved

I've written this minishell but I'm not sure I'm making a correct control of the errors. I know fgets can return feof and ferror (http://www.manpagez.com/man/3/fgets/) but I don't know how to...
Meninges asked 12/2, 2014 at 9:41

1

Solved

I have just recently started working with I/O in C. Here is my question - I have a file, from which I read my input. Then I use fgets() to get strings in a buffer which I utilise in some way. Now, ...
Credendum asked 10/2, 2014 at 13:52

1

Solved

I understand that fgets reads until EOF or a newline. I wrote a sample code to read lines from a file and I observed that the fgets gets executed more than the desired number of times. It is a ver...
Individuate asked 17/1, 2014 at 7:31

7

Solved

Specifically, the code sample here works great, but only when the string is stored in a file. Sometimes I need it to process a generated string (stored in a string variable), but I'm having troub...
Dealer asked 15/1, 2010 at 2:0

3

I have a simple question about using fgets() with char* string. .... char *temp; FILE fp=fopen("test.txt", "r"); fgets(temp, 500, fp); printf("%s", temp); .... This code didn't work well. But ...
Danicadanice asked 25/11, 2013 at 16:33

6

I want to know what is the difference between fgets() and scanf(). I am using C as my platform.
Chlorate asked 9/8, 2009 at 20:6

3

Solved

I am using fscanf to read in the date and then fgets to read the note. However after the first iteration, fscanf returns a value of -1. I used GDB to debug the program step by step. It works fine ...
Refugia asked 14/10, 2013 at 15:39

4

I'm trying to read user input and store it as a string including the whitespace. I did a search for a solution and was pointed to fgets() or scanf(%[^\n], str). But both these solutions give me an ...
Penicillium asked 14/8, 2011 at 23:57

1

Solved

I try to use file_get_contents form PHP but it's not working. There is my code : $filename = "/opt/gemel/test.txt"; if($filecontent = file_get_contents($filename)){ $nom = fgets(STDIN); fil...
Headreach asked 12/7, 2013 at 12:32

6

Solved

I'm trying to open a file, and read from it.. but I'm having some issues. FILE *libFile = fopen("/Users/pineapple/Desktop/finalproj/test242.txt","r"); char wah[200]; fgets(wah, 200, libFile); prin...
Claudclauddetta asked 17/11, 2010 at 19:55

2

I'm writing a function that perform some authentications actions. I have a file with all the user_id:password:flag couples structured like this: Users.txt user_123:a1b2:0 user_124:a2b1:1 user_125...
Ikon asked 18/3, 2013 at 18:23

1

Solved

I was wondering if there is any way to ignore whitespace with either the fscanf or fgets function. My text file has two chars on each line that may or may not be separated by a space. I need to rea...
Harar asked 9/11, 2012 at 21:29

1

Solved

I have been following a tutorial on how to make my own shell but I have been stuck for a couple days now. Two things: When this code is compiled and ran, it will randomly have segmentation fault...
Schade asked 3/10, 2012 at 20:22

6

Solved

I'm trying to compare two strings. One stored in a file, the other retrieved from the user (stdin). Here is a sample program: int main() { char targetName[50]; fgets(targetName,50,stdin); cha...
Apothem asked 8/3, 2010 at 21:13

4

Solved

For unknown reason, result of running my C program is quite unexpected. I think that it has to be some kind of a beginner mistake, however I can't find out really, where is it. #include <...
Ashton asked 24/8, 2012 at 11:21

2

Solved

I have this following scenario. I create a pipe. Forked a child process. Child closes read end of the pipe explicitly and writes into the write end of the pipe and exits without closing anythi...
Janice asked 6/8, 2012 at 10:24

4

Possible Duplicate: Why does printf not flush after the call unless a newline is in the format string? (in C) I am getting a problem using printf and fgets as in my code printf is wri...
Pyrophotometer asked 20/7, 2012 at 7:52

4

Solved

i have to write a program in C to read a file containing several line of text, each line contains two variables: a number (%f) and a string: EX: file.txt ============ 24.0 Torino 26.0 Milano 27.2 ...
Mcwherter asked 23/6, 2012 at 9:50

2

Solved

Here is the code that I am using: if (!($fp = fsockopen('ssl://imap.gmail.com', '993', $errno, $errstr, 15))) echo "Could not connect to host"; $server_response = fread($fp, 256); echo $server_re...
Lantana asked 4/5, 2012 at 13:12

2

I was wondering if anyone out there knew how this could be done in PHP. I am running a script that involves opening a file, taking the first 1000 lines, doing some stuff with those lines, then the ...
Toiletry asked 26/3, 2012 at 18:14

2

Solved

I am reading from file of format 1 32 43 23 32 43 123 43 54 243 123 2222 2 Here is my code snippet. string[100]; while(!feof(fp)) fgets(string,100,fp) Now, when I put every string, in the l...
Ransom asked 24/2, 2012 at 16:20

4

Solved

I have a question concerning fgets and fscanf in C. What exactly is the difference between these two? For example: char str[10]; while(fgets(str,10,ptr)) { counter++; ... and the second example:...
Nadianadine asked 18/1, 2012 at 21:17

2

Solved

If I type å in CMD, fgets stop waiting for more input and the loop runs until I press ctrl-c. If I type a "normal" characters like a-z0-9!?() it works as expected. I run the code in CMD under Wind...
Caucasus asked 30/11, 2011 at 18:58

5

Solved

So, I'm trying to find a way to fgets() a specific line in a text file in C, to copy the contents of the line into a more permanent buffer: Essentially, I was wondering if there was a way to do th...
Coenosarc asked 17/11, 2011 at 22:14

2

Solved

Why does this particular piece of code return false on the strstr() if I input "test"? char input[100]; int main() { fgets(input, 100, stdin); printf("%s", input); if(strstr("test message", i...
Lectra asked 30/10, 2011 at 2:56

© 2022 - 2024 — McMap. All rights reserved.