Questions tagged [fgetc]

Anything related to C or C++ standard library functions `fgetc` (C) or `std::fgetc` (C++). These functions are used to read a single character from a stream.

Anything related to C or C++ standard library functions fgetc (defined in <stdio.h> C standard header) or std::fgetc (defined in <cstdio> C++ standard header). These functions are used to read a single character from a stream.

See CPPreference.com:

294 questions
0
votes
2 answers

C fgetc sigsegv - skipping to end of line

I'm reading a file char by char. When I reach a colon I want to skip past all characters until I reach a newline character. Effectively, after seeing a colon I wish to skip to the next line (if another line exists). Seems simple enough, but I'm…
user2745184
0
votes
2 answers

Using fgetc to read words?

I want to read a text file, character by character, and then do something with the characters and something with the words. This is my implementation: char c; char* word=""; fp = fopen("text.txt","rt"); do { c = (char)fgetc(fp); if(c == ' '…
user2154420
  • 442
  • 4
  • 17
0
votes
1 answer

fgetc without incrementing pointer OR decrementing the fpos_t object (C)

So I couldn't find the answer to this question. Is there either: A function similar to fgetc that retrieves the character at the pointer, without incrementing the pointer? OR a way to decrement the fpos_t object without decrementing the pointer…
theamycode
  • 219
  • 3
  • 10
0
votes
3 answers

Trouble getting fgetc working

I am learning C and practicing by writing a small program that reads integers from a textfile and stores them into an array. However, the integers never get stored somehow and the array is empty. int readNumbers(int array[], char* fname) { …
mrQWERTY
  • 4,039
  • 13
  • 43
  • 91
0
votes
2 answers

C detect the last new line at the end of the file

I can't detect the new line after just before the end of the file if the new line have text on the previous line. I can detect the new line 4 1 some text 2 some text 3 4 But not the new line 3 with this type of file 1 some text 2 some…
mpgn
  • 7,121
  • 9
  • 67
  • 100
0
votes
3 answers

C++ Something better than fgetc?

I have a huge file, which I'm reading with fopen & fgetc in a loop. It takes around 6 seconds to read the entire file with "rb" flag in fopen, there are around 25k lines in the file. I was wondering; what are faster ways than fgetc ? is it better…
Raúl Sanpedro
  • 266
  • 4
  • 15
0
votes
1 answer

fgetc Always returns EOF

While Trying to count the number of lines in a text file, I noticed that fgetc is always returning EOF. This code was working on Freebsd 10 but now it's not working on Mac OSX. I checked the file to see if it was empty, it's not, it's about 1 KB in…
2trill2spill
  • 1,333
  • 2
  • 20
  • 41
0
votes
0 answers

curious segmentation faults

I wrote a program that worked well without any errors. I read a text file and write the contents to an array (line by line and seperat strings in this line one by one). Then I added a second textfile and again tried to read the content but then I…
smaica
  • 723
  • 2
  • 11
  • 26
0
votes
1 answer

How can I safely and simply read a line of text from a file or stdin?

Given that fgets only sometimes includes a linebreak, and fscanf is inherently unsafe, I would like a simple alternative to read text line-by-line from a file. Is this page a good place to find such a function?
jimmetry
  • 2,141
  • 2
  • 16
  • 12
0
votes
2 answers

Weird end values when reading from file using fgetc()

I'm using fgetc() to read a char from a file which consists of digits only. Then I convert the characters to int and print it out. That's fine. But after printing out all the digits, at the end I get -38-49 values. I googled it, but nothing about it…
kulan
  • 1,353
  • 3
  • 15
  • 29
0
votes
1 answer

C++ read another line with fgets

I am coding in c++ for the nintendo ds and must use the "FILE" type to access a text file. So I'm using fgets to view the contents of the text file but I don't see any way to view the contents of anything but the first line, looking in the…
Matthew D. Scholefield
  • 2,977
  • 3
  • 31
  • 42
0
votes
1 answer

scanf %c and fgetc(stdin) influence

i have an issue with two pieces of code which are nearly the same, but i don't know why they don't behave the same. Here is the first one : printf("Type something : ); scanf("%d", &nb); scanf("%c", &c); Here is the second one : printf("Type…
Thomas
  • 11
  • 4
0
votes
1 answer

fgetc starting point for c

So I am currently getting a Segmentation fault for my code and am trying to narrow down what It could be. I am unsure if the fgetc function's starting point follows the same positioning as fprintf and scanf. i.e If I have used scanf on a file and…
user3428723
0
votes
2 answers

fgetc() not working as I had hoped

I hope i don't get voted down to quickly for this, but I have a project I'm working on for school in which I have to build a spell checker. I decided to use a trie, and it seems to be working, but I have a bug I can't find. I think the issue is in…
Joe Million
  • 147
  • 9
0
votes
0 answers

fgetc gets invalid letters

Im working on a encryption-decryption program, that uses a modified Vigenére cipher. Namely i switch out the Vigenere square after encrypting/decrypting 5 letters. It works well if the text is short but with longer texts fgetc() starts returning…