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
-2
votes
2 answers

C - Reading from a file

I have a text file containing the following: ANT. Small insect, sometimes has wings on its back. BEAR. Large beast. I have a c program: int main(void) { FILE *fp; int c; fp = fopen("myfile.txt","r"); if(fp == NULL) { …
JayJay5
  • 3
  • 2
-2
votes
1 answer

Not printing first 5 characters of the file

The loop that reads from the file and prints the result is not printing the first 5 characters from all files read. If I print them 1 character at a time it works fine, but I'm reading floating point numbers from a file which I need to be processed…
-2
votes
1 answer

C compile error - "fgetc & fputc too few arguments"

I'm new to C and struggling to see why this won't compile. The script should take two text files as args - read the first and copy the contents to the second. I'm getting the following error at compile: root@debian:/home/kevin# gcc -Wall mycat.c -o…
COOLBEANS
  • 729
  • 3
  • 13
  • 31
-2
votes
1 answer

saving and transfering data from one text file to another

Having problems with transferring a data from one text file to another. My idea is to transfer it per character but it seems to not be working. I have added these codes at the beginning FILE *addressPtr; FILE *ressPtr; and addressPtr =…
-2
votes
1 answer

How to use fgetc to read a file

I am sorry the question was not very clear and the code i have so far is shown below and i am just stuck on how i can use the while loop to print the contents of the file. #include int main() { FILE *number; /* Open the file 'numbers'…
user2960049
  • 19
  • 1
  • 2
-3
votes
1 answer

C fgetc weird behavior when simultaneously used as parameter to same function

I'm using fgetc to read and validate a stream from text file, one character at a time, but for some reason it reorders the characters. The text file contains something like "abc" void newFunction(int i, int j, int k); int main() { FILE *fp; …
reiallenramos
  • 1,235
  • 2
  • 21
  • 29
-3
votes
1 answer

I'am getting a Segmentation fault while using fgetc(). How can I fix it?

I want to read from a filestream for z bytes. Then I want to give the value in a char array back. I would appreciate it if you could give me an explaination. That's my code since now: char * getData(FILE * fp, long * x) { int z = 0; char * data…
missjohanna
  • 293
  • 1
  • 2
  • 15
-3
votes
1 answer

fgetc reads character with value = -1

fgetc() function reads characters from a text file in Ubuntu. the last character before EoF is with code = -1. what the heck is that? in text editor file seems ok, no strange symbols at end. while (!feof(fp)) { c = fgetc(fp); printf("%c…
user5672542
-5
votes
2 answers

How to read these mixture of data in C

I have to store each data in an array. How do I read these data from a file? 120 5.0000000000000000E-01 -5.0000000000000000E-01 5.0000000000000000E-01 5.0000000000000000E-01 -5.0000000000000000E-01 -5.0000000000000000E-01…
1 2 3
19
20