Jump to content

what's eof in c

ilyas001

hi guys .to make it simple i understood nothing what he is doing here 

hope you explain to me this line part by part thanks guys .

buffer.PNG

Link to comment
Share on other sites

Link to post
Share on other sites

EOF = End of File

 

So basically that program is just reading from STDIO (ie: console),  and will keep reading until it encounters "\n" (which has a specific meaning in C), or the EOF symbol.  Hence, "flushing input".

 

getchar() is just like getc(), instead it defaults to reading from STDIO instead of taking a file descriptor.

Link to comment
Share on other sites

Link to post
Share on other sites

17 minutes ago, Mark77 said:

EOF = End of File

 

So basically that program is just reading from STDIO (ie: console),  and will keep reading until it encounters "\n" (which has a specific meaning in C), or the EOF symbol.  Hence, "flushing input".

 

getchar() is just like getc(), instead it defaults to reading from STDIO instead of taking a file descriptor.

yeah you made it even more confusing sorry i really didn't get your explanation cause i'm new her so please take your time with me and put all the details 

i have a buffer problem with a char string so i need to find the \0 not the eof or even the \n what have they to do her in the first place why ? thanks for your time 

Link to comment
Share on other sites

Link to post
Share on other sites

/0 is for null terminated string. Basically it is a null character at the end of the string to show the end of the string. Without it the length of the string would border on the infinite.

CPU: Intel i7 - 5820k @ 4.5GHz, Cooler: Corsair H80i, Motherboard: MSI X99S Gaming 7, RAM: Corsair Vengeance LPX 32GB DDR4 2666MHz CL16,

GPU: ASUS GTX 980 Strix, Case: Corsair 900D, PSU: Corsair AX860i 860W, Keyboard: Logitech G19, Mouse: Corsair M95, Storage: Intel 730 Series 480GB SSD, WD 1.5TB Black

Display: BenQ XL2730Z 2560x1440 144Hz

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, ilyas001 said:

yeah you made it even more confusing sorry i really didn't get your explanation cause i'm new her so please take your time with me and put all the details

 

4 hours ago, ilyas001 said:

hope you explain to me this line part by part thanks guys

 

If you don't understand the code in the OP, you need to get a better tutorial, as it's apparently glossing over a lot of important concepts.

 

https://en.wikipedia.org/wiki/End-of-file

http://www.tutorialspoint.com/cprogramming/c_input_output.htm

https://www.tutorialspoint.com/c_standard_library/c_function_getchar.htm

http://www.pixelbeat.org/programming/stdio_buffering/

https://www.gnu.org/software/libc/manual/html_node/Stream-Buffering.html#Stream-Buffering

Link to comment
Share on other sites

Link to post
Share on other sites


\n  is new line  (one of the two characters that are introduced in files when you press ENTER)

Traditionally enter is CRLF , carriage return and life feed (advance on text line and reposition the cursor at the beginning)

 

EOF is end of file,

In the DOS days, it was also a character ... see https://en.wikipedia.org/wiki/End-of-file

You would press Ctrl + Z to close a file ... you can still do this in the command prompt: COPY CON file.txt    CON is a special keyword for console, the command prompt window, so the command will copy anything you type in the console window into the file, until you press Ctrl+Z

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×