fgetc Questions

5

Solved

I opened a file, the stream is found at the address of pointer ptr. I am attempting to see whether or not a file is blank. Using the following if (fgetc(ptr) != EOF) works as expected. When the ...
Calx asked 22/3, 2016 at 20:38

3

Solved

Certainly fgetc() returns EOF when end-of-file or an input error occurs. Is that all and does that mean no more data is available? FILE *inf = ...; int ch; while ((ch = fgetc(inf)) != EOF) { ; } i...
Agnostic asked 6/1, 2022 at 23:56

6

Solved

when the following code is compiled it goes into an infinite loop: int main() { unsigned char ch; FILE *fp; fp = fopen("abc","r"); if(fp==NULL) { printf("Unable to Open"); exit(1); } whil...
Obstructionist asked 21/12, 2011 at 8:11

3

a.c #include <stdio.h> int main(int argc, char *argv[]) { int i, counter=0; char c; FILE *file=fopen("a.txt","r"); for (i = 0x41 ; i < 0x45; i++) { printf("%c(%x) ",i ,i); whil...
Shiekh asked 4/11, 2016 at 7:54

2

I would like to loop character by character from an input file that has text and numbers. I thought I could just loop char count; while( c != ' ' && c != '\n' && c != '\t' ) { c...
Mayne asked 3/2, 2016 at 8:20

3

Solved

I always use this approach int c; while ((c = fgetc(fp))!=EOF) { printf("%c", c); } As it seems to me more readable and robust. But to an answer of mine link, chux commented that if ( ...
Helen asked 18/9, 2015 at 7:45

3

Solved

We often use fgetc like this: int c; while ((c = fgetc(file)) != EOF) { // do stuff } Theoretically, if a byte in the file has the value of EOF, this code is buggy - it will break the loop earl...
Maleate asked 17/9, 2015 at 23:11

2

Solved

I was trying to understand some basic code and got slightly confused by following code int main () { FILE *fp; int c; int n = 0; fp = fopen("file.txt","r"); if (fp == NULL) { perror("Error...
Bookmobile asked 17/9, 2015 at 22:20

1

Solved

Hi i don't know how to simulate my own Cat function in C, i know how it works when no arguments are set and i already get it, but my problem is when i tried to open a file and then print itself... ...
Pernod asked 5/5, 2015 at 23:30

4

When using fgetc to read the next character of a stream, you usually check that the end-of-file was not attained by if ((c = fgetc (stream)) != EOF) where c is of int type. Then, either th...
Wolof asked 30/4, 2015 at 19:12

4

Solved

How to read a string one char at the time, and stop when you reach end of line? I'am using fgetc function to read from file and put chars to array (latter will change array to malloc), but ca...
Depredate asked 18/5, 2014 at 20:50

3

Solved

Everywhere I see "it is practically identical", or something similar... From The GNU C Programming Tutorial : There is another function in the GNU C Library called fgetc. It is identical to get...
Morgun asked 28/8, 2013 at 6:40

2

Solved

I am creating an archive program in C, and i want it to save files i provide, list and extract them. I had many issues because i used a text file for saving, and it is not the best choice if i wan...
Enface asked 10/5, 2013 at 9:23

4

Solved

I have this code while(1){ printf("hello world !\n"); fgetc(stdin); } when this runs and I enter a letter like this: hello world ! a it ignores the fgetc(stdin) in the next loop and prints ...
Jonme asked 21/8, 2012 at 22:18

2

Solved

In the book Linux System Programming I have read some like this: fgetc returns the character read as an unsigned char cast to an int or EOF on end of file or error. A common error using fgetc i...
Rundown asked 15/6, 2012 at 19:48

5

Solved

I need to read a line of text (terminated by a newline) without making assumptions about the length. So I now face to possibilities: Use fgets and check each time if the last character is a newli...
Uretic asked 3/3, 2011 at 20:58

1

The program below runs fine on various Solaris/Linux flavours, but not on AIX. However, if I replace while(c!=EOF) with while(c!=0xff) on AIX it runs completely fine. Any thoughts? I checked...
Aborn asked 20/10, 2010 at 11:23
1

© 2022 - 2024 — McMap. All rights reserved.