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

I have a problem with qsort in c while sorting database file?

I am new in programming, I want to do database sorting using qsort function in C. we have a file of 100 people, I want to sort it by their last names by reading the data from text file into database variable of 100 people and with struct. I'm new…
jaswinder
  • 23
  • 5
-1
votes
1 answer

file read using fgetc adds FF at the end

I'm reading a file using fgetc. File reading starts at an offset.At the end I see 8'hFF getting appended at the end of file.I'm expecting 6 bytes in the file but see 7 in them.I'm not sure why this is happening. Any ideas? Below is my code: module…
-1
votes
2 answers

returned value from fget(filePointer) doesn't changed

I try to extract a char by using unsigned char ch1 = fgetc(filePointer);, but the value that's returned is allways 255. Here's my code: #include #include "anotherCFile.c" int main(int argc, char **argv) { int ch; FILE*…
J. Doe
  • 95
  • 8
-1
votes
1 answer

c program terminates while reading from file

I am trying to read data from text file using different function like fgetc(), fgets() and fscanf(). During execution program terminates after reading from fgetc(). #include void writeFile(FILE *, char *); void readFile(FILE *,char…
-1
votes
1 answer

fgetc dropping characters when reading 2d pixel map with for loop

I am working on inputting a 2d pixel array from a PPM file with the one I am testing being of width and length 5. Also I am aware that in a ppm file that is rgb it has 3 color values not just one. I had forgotten that before I wrote this code, but…
-1
votes
1 answer

Identifying newline characters in a file using C

I'm trying to read a newline character in a text file and thus count the number of lines in a text document Content of .txt file: My Name Is John Output of my code: Nm s on Line number is 1 My code: #include #include
Ambareesh S J
  • 97
  • 1
  • 9
-1
votes
1 answer

How to count amount of elements on each line of a file

Im trying to read in some data from a file (ultimately into a structure, but not important for now) and to ensure that this file has equal amount of data on each line. Each line can have words or numbers though so I've converted one line of a file…
stellarhawk 34
  • 133
  • 1
  • 3
  • 11
-1
votes
1 answer

reading characters from buffer

I am scanning strings as input , i am using getline to do so e.g char *lajna=NULL; size_t dlzka=0; getline(&lajna,&dlzka,stdin); and i want to read first char using fgetc , i tried to do test=fgetc(lajna); but it throws error cannot convert…
Johnyb
  • 980
  • 1
  • 12
  • 27
-1
votes
1 answer

Why we always have to use fgetc command in C programming instead of fscanf which do the same thing but prints strange results?

In C programming whenever I use fgetc(file) to read all the chars until the end of the file it works. But when I use the similar fscanf(file, "%c") function it prints strange characters. Code: #include #include int main() { …
-1
votes
2 answers

How read lines of file and get them to array in C?

I would like to create a function to read file line by line. One every line is one name. int readConfig(char ** path, FILES ** files ) { FILE* f; f = fopen("file", "r"); int ch; while ((ch=fgetc(f)) != EOF ) { } return…
John Boe
  • 3,501
  • 10
  • 37
  • 71
-1
votes
1 answer

Program Segfaults in between 2 printf()'s

hope someone can assist. I had this program running perfectly, moved a few lines of code from one function to another and it all fell apart. I've included a snippet below from the top of the function until segfault. It happily outputs "did we get…
Xeke
  • 21
  • 2
-1
votes
1 answer

How to use read() and/or fgetc to get certain strings

Using fgetc() and/or read() how to i get the keys and the values from a file? This is how it is written in the file: And i need to put each key and value in a new array(to do linked-lists). So, to insert in the…
Elsendion
  • 187
  • 1
  • 4
  • 15
-2
votes
1 answer

unwanted random characters from nowhere in string C

I'm making a program that takes a standard text file and converts it into an HTML document. for the most part it works fine and I am just improving it's functionality now, but there is this strange thing that happens when I save the title to a…
Architect
  • 141
  • 2
  • 7
-2
votes
1 answer

How to know if the line is empty while reading char by char in PHP

How do I differentiate between an empty line and an endofline in PHP while reading character by character. In short I want to know how to find an empty line while reading char by char. Let me know if anything is unclear with a comment. Thank you...
Otag
  • 141
  • 11
-2
votes
1 answer

Reading file with fgetc and adding sentences into linked list

last three days I have a problem.. I have a file containing sentences. When I'm reading file with int maxSize = 256; int currSize = 0; int i = 0; char *sentence = (char*)malloc(maxSize); char c; currSize = maxSize; while ((c = fgetc(input)) !=…
1 2 3
19
20