www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/21/20:57:05.3

Sender: nate AT cartsys DOT com
Message-ID: <362E7AF9.9C62BCC3@cartsys.com>
Date: Wed, 21 Oct 1998 17:23:21 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.05 [en] (X11; I; Linux 2.0.35 i486)
MIME-Version: 1.0
To: djgpp AT delorie DOT com, a14616 AT aaual DOT ualg DOT pt
Subject: Re: need help reading characters from a text file
References: <362CD10B DOT 450C5960 AT aaual DOT ualg DOT pt>
Reply-To: djgpp AT delorie DOT com

Miguel Guerreiro,bioquimica wrote:
> 
> I'm trying to write a program that reads one character at a time from a
> text file
> the problems is that it either reads it from the keyboard or doesn't do
> anything.

General C questions are better posted to comp.lang.c, but since you're
here...

Use something like:

#include <stdio.h>

FILE *f;
int c;  /* Not `char'; `EOF' is outside the range of a `char'. */
f = fopen(filename, "r");  /* for "r"ead */
do {
   c = getc(f);
   if (c != EOF) do_something_with_character(c);
} while (c != EOF);
/* You've reached the end of the file */
fclose(f);

If that doesn't help, be specific about what you want to accomplish and
what you've tried.
-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019