Menu
Menu
DaniWeb
Log In
Sign Up
Read
Contribute
Meet
Search
Search
About 1,000 results for
fgetc
- Page 1
Reading Files with fgetc?
Programming
Software Development
17 Years Ago
by RexxX
… I was, now I'm learning how to use
fgetc
properly. Does
fgetc
read in a character? If so I can't…); infile = fopen(infile_name, "r"); //open file stream fchar =
fgetc
(infile); //read a character printf("The first char is…
Re: Reading Files with fgetc?
Programming
Software Development
17 Years Ago
by Aia
>I'm learning how to use
fgetc
properly
fgetc
reads a character from the stream passed and return that …
Re: fscanf vs fgetc
Programming
Software Development
11 Years Ago
by deceptikon
> My understanding of
fgetc
is it reads character by character of a file It … may not be a stream to a file. For example, `
fgetc
(stdin)` is perfectly acceptable. > They think fscanf can also… is correct. It can. The call that's equivalent to `
fgetc
` is `fscanf(stream, "%c", &myChar)`. > I…
fscanf vs fgetc
Programming
Software Development
11 Years Ago
by COKEDUDE
What is the difference between fscanf and
fgetc
? I have a few people arguing with me on the differences. I thought
fgetc
reads character by character of a file. I thought fscanf reads the whole file. Is that corrrect? Can someone elaborate on what I forgot?
Re: fscanf vs fgetc
Programming
Software Development
11 Years Ago
by deceptikon
> Is that corrrect? Not at all. Have you checked a C reference manual? The only similarities `
fgetc
` and `fscanf` have is they read input from a stream, and fscanf can simulate `
fgetc
`. The people you were arguing with, what were their points? Perhaps we can clear up any errors on both sides if you elaborate.
How to concatenate the characters read from a file with fgetc?
Programming
8 Years Ago
by Jose_12
… should I concatenate the characters read from a file with
fgetc
to determine if it is a number, keyword or an…" ) ) == NULL) { printf ( "Error opening file !"); while (( c =
fgetc
( f1 ) )! = EOF ) { if ( isdigit ( c ) ) printf ( "% c is a…
Re: fscanf vs fgetc
Programming
Software Development
11 Years Ago
by COKEDUDE
My understanding of
fgetc
is it reads character by character of a file. They think fscanf can also read character by character of a file. I do not think that is correct. I think fscanf is used for reading an entire file. I may not be explaing that with the correct terminology but I have used it for reading an entire file before.
Re: fscanf vs fgetc
Programming
Software Development
11 Years Ago
by gerard4143
One small subtle point.
fgetc
() reads the next character from stream and returns it as an **unsigned char cast to an int**, or EOF on end of file or error.
Re: fscanf vs fgetc
Programming
Software Development
11 Years Ago
by COKEDUDE
And if you need a char you always cast it like this :). while ((c =
fgetc
(pFile)) != EOF) { vertices[addcounter] = (char)c; }
C fputc and fgetc vs C++ read and write
Programming
Software Development
19 Years Ago
by Micko
…;); fp2 = fopen ("name", "wb"); while ( (buff =
fgetc
(fp1)) != EOF) { fputc(buff, fp2); } } [/code] I'm wondering how…
Re: C fputc and fgetc vs C++ read and write
Programming
Software Development
19 Years Ago
by Micko
… text and binary mode. In C implementation with fputc and
fgetc
I opened files in binary mode, so I wanted to…
fgetc help
Programming
Software Development
18 Years Ago
by balgarath
is there any way to check what mode a FILE pointer has been opened in? ("r", "w")?
Re: fgetc help
Programming
Software Development
18 Years Ago
by Ancient Dragon
No -- that information is not saved in the FILE structure.
Re: Reading Files with fgetc?
Programming
Software Development
17 Years Ago
by John A
Probably because you're outputting the 'char' as a 'char array'. [code=cplusplus]printf("The first char is %s\n", fchar);[/code] Try changing [icode]%s[/icode] to [icode]%c[/icode]. Some other things... - [icode]fchar[/icode] should be an integer. This way, you guarantee that it can hold an EOF character when the end of the …
Re: fscanf vs fgetc
Programming
Software Development
11 Years Ago
by gerard4143
How the hell would we know what you forgot?
Re: fscanf vs fgetc
Programming
Software Development
11 Years Ago
by COKEDUDE
Thank you :). Were both saying the same thing but can't explain it in a way the other understands.
Re: How to concatenate the characters read from a file with fgetc?
Programming
8 Years Ago
by deceptikon
> to determine if it is a number, keyword or an identifier This is a key statement to me, because it sounds like you're writing a lexer. If that's the case, it's not really as simple as throwing characters into an array (or some variation of \*scanf); you need to include some introspective analysis on the characters to properly tokenize …
Re: How to concatenate the characters read from a file with fgetc?
Programming
8 Years Ago
by Jose_12
yes , that is a lexer in "C" ,I have for example the next code in C #include <stdio.h> int main() { printf("Hola mundo"); return 0; } I need to identify the number, words and keywords and the output of the file will be…
Re: How to concatenate the characters read from a file with fgetc?
Programming
8 Years Ago
by AssertNull
You could keep track of the LAST character type you extractedand compare it to the current type (i.e. digit). So when you grab a '1', you don't immediately assume you are done extracting the number. You grab the next digit '2' and notice that it's a digit, so you keep going and grab the next character and it's a '3', so you keep going and grab …
Re: How to concatenate the characters read from a file with fgetc?
Programming
8 Years Ago
by Jose_12
I found another way for do my proyect I need to read a txt and store it in a dynamic string array the code I have now does but memory is wasted because it is static I like to read a txt and every word stored in a string array of dynamic #include <stdio.h> #include <conio.h> #define MAX_CHARS 20 …
Re: C fputc and fgetc vs C++ read and write
Programming
Software Development
19 Years Ago
by Ancient Dragon
only write out the number of bytes read. At some point (at end-of-file) the number of bytes read will be less than the buffer size. This would go much faster if you read/write with larger buffer size -- say 255 characters. [code] int main() { [color=red] char buf[255];[/color] ifstream fp_in("my.txt", ios_base::binary | …
Re: C fputc and fgetc vs C++ read and write
Programming
Software Development
19 Years Ago
by Narue
>copying from one file to another is a simple matter. On the surface at least. >I'm wondering how this is done in C++ A direct translation of C streams to C++ streams is: [code] #include <fstream> int main() { ifstream in ( "infile" ); ofstream out ( "outfile" ); if ( in && out ) { …
Re: C fputc and fgetc vs C++ read and write
Programming
Software Development
19 Years Ago
by Narue
>I was thinking about get and put, but I wasn't sure about text and binary mode It doesn't matter in this case.
Re: Read in file problems
Programming
Software Development
12 Years Ago
by Ancient Dragon
fgetc
() returns int, not char. >The return type is int to accommodate for the special value EOF, which indicates failure: The while loop should be this so that the rest of the code isn't run when
fgetc
() returns EOF: `while( (c =
fgetc
(myfile)) != EOF)`
please help to convert from c to c++ just??
Programming
Software Development
15 Years Ago
by yara naser
…;\n"); } /**************************************************************** Function to create lexical analysis. *****************************************************************/ void analyze() { ch=
fgetc
(fp); //Read character. while(!feof(fp)) //While the file is…
extract includes
Programming
Software Development
14 Years Ago
by Adami
…= OUT; } fputc(ch,c1_fp); break; /*IN_STRING*/ } /*switch*/ ch=
fgetc
(c_fp); } /*while*/ fclose(c_fp); fclose(c1_fp); return 0; /*dummy*/ …); } }/*frst if*/ else { fputc(ch,c2_fp); } ch=
fgetc
(c1_fp); }/*while(1)*/ fclose(c1_fp); fclose(c2_fp); }/*includes_extractor*/[/CODE]…
Re: extract includes
Programming
Software Development
14 Years Ago
by Adami
…header_fp)) /*copy header file content to *.c2 file*/ { ch=
fgetc
(header_fp); fputc(ch,c2_fp); }/*while(4)*/ fclose(header_fp); }…= OUT; } fputc(ch,c1_fp); break; /*IN_STRING*/ } /*switch*/ ch=
fgetc
(c_fp); } /*while*/ fclose(c_fp); fclose(c1_fp); includes_extractor(c1_fp, c1_file_name ,c1_file_string_len…
Re: extract includes
Programming
Software Development
14 Years Ago
by Adami
…header_fp)) /*copy header file content to *.c2 file*/ { ch=
fgetc
(header_fp); fputc(ch,c2_fp); }/*while(4)*/ fclose(header_fp); }…= OUT; } fputc(ch,c1_fp); break; /*IN_STRING*/ } /*switch*/ ch=
fgetc
(c_fp); } /*while*/ fclose(c_fp); fclose(c1_fp); includes_extractor(c1_fp, c1_file_name ,c1_file_string_len…
Database division
Programming
Software Development
12 Years Ago
by anumash
…0; while(ch1!='\n'&&ch1!=EOF) ch1=
fgetc
(fp); } } } else //if the 1st character… the first 2 chars, read the entire word... {ch1=
fgetc
(fp); count++; arr[i]=count; } } } else …
help with files
Programming
Software Development
15 Years Ago
by edenn1
…]; char c; int i; i=0; word[0]='\0'; c =
fgetc
(file); while (c != ' ' && c!=EOF && c…!='\n') { word[i]=c; i++; c =
fgetc
(file); } word[i]='\0'; return word; } FILE* openFile(char* fileName…
1
2
3
17
Next
Last
Search
Search
Forums
Forum Index
Hardware/Software
Recommended Topics
Programming
Recommended Topics
Digital Media
Recommended Topics
Community Center
Recommended Topics
Latest Content
Newest Topics
Latest Topics
Latest Posts
Latest Comments
Top Tags
Topics Feed
Social
Top Members
Meet People
Community Functions
DaniWeb Premium
Newsletter Archive
Markdown Syntax
Community Rules
Developer APIs
Connect API
Forum API Docs
Tools
SEO Backlink Checker
Legal
Terms of Service
Privacy Policy
FAQ
About Us
Advertise
Contact Us
© 2025 DaniWeb® LLC