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

FGETC library name in Fortran?

Is there a library that I can explicitly link to my Fortran code to find FGETC function? I'm getting linker errors for unresolved external symbol for the fgetc function and I tried using 'USE IFPORT' but that broke a bunch of other stuff. I am…
user1496542
  • 539
  • 2
  • 6
  • 14
2
votes
4 answers

C: Low level character formatting: (enter+newline) using fgetc

I'm working on a project on C that reads a text file and converts it to an array of booleans. First I read the file to a string of size n (is a unsigned char array), then I use a function to convert that string to a boolean array with size n * 8.…
1
vote
3 answers

Reading input from fgetc() and printing with printf()

Okay, I'm sure there's something I'm missing here, but I have no idea what it is and I'm hoping someone could help me figure it out. I'm reading in input from the command line and was writing a function that uses fgetc() to do so. However, a…
user1227489
  • 33
  • 1
  • 4
1
vote
5 answers

Implementing fgetc; trying to read word by word

I am trying to read word by word, and below is the logic that I have adopted. This is reading in the words fine, except when it gets to the last word in a line, in which it stores the last word of the current file AND the 1st word of the next new…
smooth_smoothie
  • 1,319
  • 10
  • 27
  • 40
1
vote
2 answers

what is the output of fgetc under the special case where int width == CHAR_BIT

In section 7.19.7.1 of C99, we have: If the end-of-file indicator for the input stream pointed to by stream is not set and a next character is present, the fgetc function obtains that character as an unsigned char converted to an int and…
tyty
  • 839
  • 5
  • 12
1
vote
1 answer

fgetc reference variable

I'm playing a bit of fun code golf, and I'm running into an issue: Golfed:
Korvin Szanto
  • 4,531
  • 4
  • 19
  • 49
1
vote
0 answers

Why do I need to add one more fseek() function in my code after fgetc() function?

In my problem I was using fseek() function to read a character from the 4th position. After that I wanted to write a new character after that position where the file pointer is pointing to. As after the first call of fseek() function my pointer is…
1
vote
1 answer

Storing mac addresses and device names listed in a text file into a struct array using C

I am trying to take a list of MAC Addresses and Device names from a text file and store them in an array called list; struct list { char ch; char a[2], b[2], c[2], d[2], e[2], f[2], g[2], alias[32]; //chars a-g are supposed to be a maximum…
1
vote
2 answers

File reading with fgetc in C

I have a simple file reading algorithm but it's not returning the values that are in the file. The below is the code. The input txt values are 200 53 65 98 183 37 122 14 124 65 67 but the code is returning 48 48 32 53 51 32 54 53 32 57 56 32 49 56…
evie
  • 73
  • 1
  • 8
1
vote
2 answers

fgetc vs getline or fgets - which is most flexible

I am reading data from a regular file and I was wondering which would allow for the most flexibility. I have found that both fgets and getline both read in a line (one with a maximum number of characters, the other with dynamic memory allocation).…
tintins7a6164
  • 188
  • 1
  • 7
1
vote
2 answers

how to print line numbers from multiple files without using fgets

I'm trying to print line numbers in the beginning of the lines without using fgets() yes, it prints line number well when I input multiple files but I want to get result like this. Can you guys help me with this? Now result 1 I'll always remember 2…
1
vote
1 answer

How to load 2D char array from file and print it with mvprintw() in C using ncurses.h?

I'm coding a small game and i decided to load a map from the file but I'm facing a problem.The file looks like this : and i need to print it like it is in the file expect of dots. They has to be spaces. my code for print looks like this : void…
1
vote
1 answer

Read and save each word of a txt file using C?

I'm trying to write a program that : open a txt files read the first word of a line and store it in a variable (or an array) => it'll be a name read the second word of a line and store it in a var/array => it'll be a college department do it for…
user17356067
1
vote
2 answers

My fgetc is not returning a desired output. (C programming beginner)

My .txt file I have created before running the code looks like the following: /* I am Jason and I love horses hahaha/n This is amazing, How much I love horses, I think I am in love/n how many people love horses like I do?/n/n this is quite a…
1
vote
1 answer

Why does fputc() append to my file and not overwrite it?

I'm writing a C Program that changes all uppercase characters to lowercase from a certain file. The problem is, after storing all characters (processed) in a string, and trying to print all characters inside that file, they are appended to that…
Mateaș Mario
  • 113
  • 1
  • 7