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
1 answer

fget not reading full line sometimes in PHP '<' symbol effecting fgets line read

PHP fgets function is not reading the following text file lines fully. I'm using fgets to read line by line of some data. Lines that fail to read fully are as follows; %107A195U
007
  • 21
  • 4
0
votes
1 answer

Command "who -b" behaves differently

I am trying to parse system boot time from "who -b" output. #define _XOPEN_SOURCE #include #include #include #include #include void GetSystemTurnOnTime() { FILE *fp; char *pTemp = NULL; char…
user4742958
0
votes
3 answers

Reading from a file and setting an offset?

I am new to C, and I am trying to build a C program that scans through a file until EOF, picks out lines that contain a certain keyword and then sets an offset after the last line was searched. When the scan is executed again, it scans the file,…
roxycandigit
  • 1
  • 1
  • 2
0
votes
1 answer

Getting garbled output from fgets() in C

#include int main(int argc, char *argv[]) { FILE *fp = fopen("sss", "w+"); char buf[100]; fputs("hello, world", fp); fflush(fp); fgets(buf, 100, fp); fputs(buf, stdout); fclose(fp); return 0; } Can someone teach me what's…
tian tong
  • 793
  • 3
  • 10
  • 21
0
votes
3 answers

Issues while inputting strings in C

I am trying to write a C program that takes n as an integer input and then inputs n strings. The problem that when I run the program, it takes one input less than n. If I enter 1 as the first input the program just terminates. Here is the code : int…
helios_xt
  • 87
  • 8
0
votes
1 answer

Using fgets and strtok to read in data and create linked list

Need some help with reading in lines of data from a text file using the fgets and string tokenization commands, which will then be used to create a linked list. I've followed some examples I've found on Stack Overflow and other tutorial websites,…
Minhaz M
  • 19
  • 3
0
votes
1 answer

C: Segmentation fault while reading user input with fgets

I'm new to C and I'm trying to write a program with a lot of user input. For that purpose I wrote this function: char * addValue(char * msg){ char * input[80]; printf("%s", msg); fflush(stdout); fgets(*input, 80, stdin); …
Marcel Kapfer
  • 573
  • 4
  • 13
0
votes
1 answer

Fgets compilation error

I'm stuck with what seems a beginner's compilation error: My simple program: #include #include #include "Tiles_Circular_Linked_List.h" #define MAX_LINE_LENGTH 128; int main(int argc, char **argv) { struct node *head_tail; …
Max Segal
  • 1,955
  • 1
  • 24
  • 53
0
votes
4 answers

Indexing in arrays when using fgets

I'm teaching myself programming. I read that a string stored in an array of characters can be indexed to extract the nth character. However, I've been trying to solve this for hours: I realized trying to solve an exercise that I can only access the…
evar_3712
  • 1
  • 1
0
votes
1 answer

C: using fgets() to read from file

I currently have this> FILE *in=fopen("some_file.txt", "r"); char input[3]; int i=0, j=0; if(in!=NULL) { fgets(input, sizeof(input), in); initialize(input); } while(j<100) { fgets(input, sizeof(input), in); addNode(head,input); …
Rorschach
  • 734
  • 2
  • 7
  • 22
0
votes
2 answers

Can't understand why this causes an error

I have a large directory of music which is listed in a file called op. I have been able to build a command which will randomly pick a song from the op file using some creative math with the nanosecond output from the date command. It works fine…
Deanie
  • 2,316
  • 2
  • 19
  • 35
0
votes
1 answer

Problems with readdir() and fgets

I'm writing a code where I can be given a directory of .txt files, and specific strings that appear throughout each file, and do some simple comparisons. code chunk will be posted below. So, My task:Open directory>open file>compare strings>open next…
Liam King
  • 1
  • 1
0
votes
1 answer

Convert char array into double

I have tried this: #include #include int main(int argc, char *argv[]) { FILE *txt1; char tam[13]; char tam1[13]; char tam2[13]; txt1 = fopen("C:/Users/Hugo/Documents/C/in2.txt","r"); if(txt1 == NULL) { printf("No se puede…
0
votes
2 answers

C: use of fgets() with file

Good evening StackOverFlow. I typed a code which uses lists and files to manage an address book, now I have a problem with the function fgets(). In the procedure print_file() I used fgets() to read a line from the file and to store it into a string…
0
votes
1 answer

Segmentation fault while trying to test fgets()

I'm trying to write a program to experiment with the fgets() function, with which I have little experience. I keep getting a segmentation fault 11 error when I run the program (but no errors when I compile it) and I don't know enough about fgets to…
Frank Tocci
  • 616
  • 2
  • 8
  • 20