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

Is this a valid use of fgetc?

My input stream is from a text file with a list of words separated by the \n character. The function stringcompare is a function that will compare the equivalence of two strings, case insensitive. I have two string arrays, word[50] and dict[50].…
0
votes
1 answer

method that returns char with int

Can someone explain this method to me and why is this returning char instead of int?? public static int fgetc(InputStream stream) { char ToRet = '\0'; if (InStream.isEmpty()) { try { ToRet = (char)…
cohsta
  • 187
  • 1
  • 4
  • 14
0
votes
0 answers

Valgrind, invalid read, fgetc

Good evening everybody. I have written a function that is checking values that come from a stream by analyzing each character. If the character has the value of a specific sign the code should do something deeper in the program. Everything works…
J. Bug
  • 152
  • 1
  • 10
0
votes
2 answers

Read binary and txt File - 1 byte at a time

I am trying to write a code which reads 1 byte (ideal goal is n bytes but starting with 1 byte - so for n bytes if its easier please suggest) Below is the code I have attempted to read 1 byte at a time and output it in hex format. But all get is…
oneday
  • 629
  • 1
  • 9
  • 32
0
votes
3 answers

File in c language

I need help about my code, I got some works, and it is one of the assignments. suppose an encrypted file was created using the encoding/decoding scheme. Each letter is substituted by some other letter according to a given mapping as shown…
Han
  • 27
  • 1
  • 3
0
votes
2 answers

Allocating memory dynamically without knowing the size of the string which is going to be entered

Below is the function which returns a character pointer to a string which was initialized using getc(stdin)- character by character. Is there any flaw in memory allocation method? Is this an efficient way when we don't know the size of the string…
Tharun
  • 425
  • 5
  • 13
0
votes
1 answer

Issues reading string from file with fgetc C (without use fscanf,etc)

I'm trying to read just a string until a space occurs from a file using fgetc. I could not use fscanf and other i/o functions because I have to know if a line feed is read. A function call leerString(string,f) should change the string variable…
0
votes
1 answer

Error in counting the number of times a character appears in a file in Case insensitive manner

Please tell me what is wrong with below code. After executing it is showing "test.txt has 0 instances of letter 'r'" `#include #include #include int main() { FILE *fp; char ch,cmp; char f[100]; int…
0
votes
1 answer

Deleting null character from a file

When writing in a file, I generate several null characters /00 each time a new write operation is performed. Bellow it is my approach to tackle this task, but it does not work. File content: foo\00\00\00\00\00\00 Code approach: int aux; while((aux =…
qwerty
  • 486
  • 1
  • 11
  • 37
0
votes
2 answers

scanf,fgets, fgetc get skipped inside loop

Im trying to make a recursive menu. This program will later work with a tree(hojanodo), thats why I keep track of the root. Problem: For some reason the fgets/fgetc is being skipped inside the recursivity on the second run, why does this happen? I…
Goma
  • 21
  • 5
0
votes
0 answers

C - fgets read past newline

I am trying to read a file in increments of 10 and store them in an array. I use a loop to read like this: char storeArray[11]; while(!foef(input)){ fgets(storeArray, 11, input); } I need to store 10 characters at a time in the array but fgets…
Logan M
  • 348
  • 2
  • 12
0
votes
1 answer

PHP get the last line of an open file handle with multiple lines

This seems like it should be a simple thing to do but I'm having a bit of trouble with fgetc() when returning the last line of a open file handle. what I'm trying to do is return the last line written to the handle, I have the following which works…
tomo661
  • 88
  • 4
0
votes
3 answers

C - Making sure user input is of appropriate length

Something that I thought that would be pretty basic has me stumped. If I have a char array char menuInput[3]; and do fgets(menuInput,3,stdin);, I can easily check if they entered nothing: if(menuInput[0]=='\n') { printf("******You made no…
AUS_Doug
  • 39
  • 8
0
votes
0 answers

PHP fgetc can't read apostrophe from my file

I've been searching for this question, but I think it haven't been asked yet. I have got a problem with reading via fgetc() from my file. When I need to read the apostrophe, the program replace it with ???, so I am not able to add apostrophe to my…
SRewip
  • 107
  • 5
0
votes
5 answers

issue fgetc() c using while loop

I got a big problem using fgetc() and i can't figure it out... I try to parse a text file, everything compile but at the execution I got an infinite loop or a segfault (Code::blocks), my text file is like that: {"USD_EUR": "0.8631364", "EUR_USD":…
mel
  • 2,730
  • 8
  • 35
  • 70