LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-05-2004, 01:15 PM   #1
ThePenguin
Member
 
Registered: Sep 2003
Location: GA, US
Distribution: RedHat 9.0
Posts: 50

Rep: Reputation: 15
EOF character for Mandrake 10?


What is the EOF character for Linux Mandrake 10.0? I have a program i'm running and when I ran it...I suddenly remembered a vital thing....lol....How do I end it using EOF? I programmed EOF into the program to be the ending character to a loop.

So EOF? <<<(I love that smiley)
 
Old 09-05-2004, 02:00 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
EOF defined in <stdio.h>

Hi -

The way you detect "end of file" usually depends on the library you're using to read the data, not on some "sentinel" value in the file itself.

If you have a 'C' or C++ program using the standard library, you'd declare your input variable type "int" (even though you're reading "char" values from the file) and look for the "special value" EOF (#define'd in <stdio.h>).

Here's an example:
Code:
#include <stdio.h>
#include <errno.h>

int
main (int argc, char *argv[])
{
  FILE *fp = NULL;
  int c;  /* NOTE: even though we're reading "char", we 
             need to declare an "int" in order to detect EOF */

  /* Check command line usage */
  if (argc < 2)
  {
    printf ("USAGE: %s <filename>!\n", argv[0]);
    return 1;
  }

  /* Open file */
  fp = fopen (argv[1], "r");
  if (fp == NULL)
  {
    printf ("ERROR: Could not open file %s, errno %d\n", argv[0], errno);
    return 1;
  }

  /* Read file until EOF */
  while ( (c = getc (fp)) != EOF)
  {
    printf ("char: %c:0x%02x\n", c, c);
  }

  /* Close file */
  fclose (fp);
  printf ("Done reading %s.\n", argv[0]);
  return 0;
}
'Hope that helps .. PSM
 
Old 09-05-2004, 02:39 PM   #3
ThePenguin
Member
 
Registered: Sep 2003
Location: GA, US
Distribution: RedHat 9.0
Posts: 50

Original Poster
Rep: Reputation: 15
I dont quite understand what you mean I didn't get much sleep last night. (stayed up configuring-which was an amazing success...Everything working in one night) Here is the program I am compiling~It is, of course, C++:

edited

Ctrl+D on a new line ends the program (It is the EOF character )

Last edited by ThePenguin; 09-05-2004 at 03:14 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
EOF finding Goblin_C_Noob Programming 7 09-10-2005 09:58 AM
eof ... c ... linux xviddivxoggmp3 Programming 6 03-31-2004 12:56 PM
Question about EOF (C) xailer Programming 6 12-07-2003 11:15 AM
character encoding - mandrake 9.2 Osten Mandriva 1 11-21-2003 11:09 AM
<< Eof ? sikandar Linux - Software 5 09-18-2003 11:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration