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

fgetc omit characters and then assign integer

I've a file data.dat HI5 LO2 from which I want to read 5 and 2, and store them as uint16s. I've written #include int main() { unsigned short int high; FILE *pFile; pFile = fopen("data.dat", "r"); int c; while(c !=…
0
votes
2 answers

"Walking " through file making changes, PHP

I want to replace each character in file with another one by one "walk" through the file. It is like using fgetc(), but I also need to replace that char. My file is big, which is the best way to do this? Any advice?
Hurrem
  • 193
  • 2
  • 4
  • 15
0
votes
1 answer

C: Count `new line` until double space is reached

Basically I am trying to read a "block" of data from a file that looks something like 000000000 000000001 000100000 100000000 000000000 000000000 000000000 The above example would translate into TWO blocks of data. First one is 4 lines tall,…
40pro
  • 1,283
  • 2
  • 15
  • 23
0
votes
2 answers

How to read in object files in C?

Let's say there's an object file input.obj. In the terminal, if I do "cat input.obj," it returns some random characters like "???A?J." But when I "hexdump" it, it shows the values I want to read in into my program. I read in this obj file into…
Mariska
  • 1,913
  • 5
  • 26
  • 43
0
votes
1 answer

c debug assertion for calling fgets/fgetc/feof

hey sorry for bothering if this is a really simple issue, but I can't seem to solve this debug assertion failure after so many different trials. I'm merely executing the following code. I have tried using fgets, fgetc or even feof to wrap around the…
Henry Cho
  • 770
  • 2
  • 15
  • 33
0
votes
2 answers

C: edit file to remove null characters:

I thought this would be an easy task, after a couple of tries I try the tried and true write to a temp than reopen and rewrite: #include #include int main() { FILE *f = fopen("main2.c","r"); FILE *t =…
jason dancks
  • 1,152
  • 3
  • 9
  • 29
0
votes
2 answers

fgetc read file line by line

So I'm working on a function that will use fgetc to read a line into a buffer. so I can use that buffer as I please, and then refill the buffer with the next line. My function works however I have to repeat code outside of the for loop to process…
Keith Miller
  • 1,337
  • 1
  • 16
  • 32
0
votes
2 answers

File reading and character counting

I'm trying to read in a file and then output the file by characters. I want the user to enter a number which will be the number of lines to be displayed. Without the following line, my code will display the entire text file. if (y == lineCount)…
blitzeus
  • 485
  • 2
  • 10
  • 28
0
votes
2 answers

Cant seem to get fgetc working the second time reading a file

I'm reopening and reading a file, SORTED.txt, after closing it from its first time use - copying all the contents of another file, UNSORTED.txt. After copying from UNSORTED.txt, I wanted to count the number of lines of what I've copied (as a…
bomp
  • 309
  • 1
  • 4
  • 12
0
votes
1 answer

read char from file

I would like to know why my program gets wrong result. I just need to read characters from file including white space, (.), (,), and others and output them in particular string format. As a result I get more 300 instances of char read and their…
Ali Folks
  • 11
  • 1
  • 4
0
votes
4 answers

C: Handling fgetc input from file streams

OK, I'm working on a spellcheck program in C. The bit I'm having trouble with is reading a word from the system dictionary into the program. I've searched for an answer but I couldn't find anything quite right, probably because this is a pretty…
Aj_76
  • 39
  • 2
  • 12
0
votes
3 answers

fgetc() doesn't work properly

I have file that goes like 7 4 5 1 etc. I want to put these number in a multi-dimensional array. for(x=0;x<9;x++) for(y=0;y<9;y++) { current=fgetc(fp); if(current!=EOF¤t!=' '¤t!='\n') …
baris_ercan
  • 152
  • 2
  • 16
0
votes
2 answers

C - using fgetc to store value in enum 'class'

I am writing a program that accepts a file with database entries in it. The entries are all in the same format, with the data in the same order. The first number in the file is the number of entries. Then the data looks like this: LastName…
manalishi
  • 101
  • 3
  • 12
-1
votes
1 answer

`fseek` issue when printing last $N$ lines to a file using C++

I'm using the following code to print last N lines of one file to the other. #include #include #include using namespace std; void printLastNLines(const std::string& inputFileName, const std::string& outputFileName,…
ubaabd
  • 435
  • 2
  • 13
-1
votes
1 answer

Why does fgetc() in C always reads extra, non-existent characters whenever I try to read non-printable characters from txt files?

I am trying to read non-printable characters from a text file, print out the characters' ASCII code, and finally write these non-printable characters into an output file. However, I have noticed that for every non-printable character I read, there…
Yooshinhee
  • 25
  • 4