delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/12/14:17:41

From: phreadd AT powerup DOT com DOT au (David Orme)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: writing a program that reads .txt files
Date: 12 Jun 1997 08:56:52 GMT
Organization: Power Up
Lines: 52
Message-ID: <5nodkk$h34$1@grissom.powerup.com.au>
References: <Pine DOT OSF DOT 3 DOT 95 DOT 970611151232 DOT 6412A-100000 AT unicorn DOT it DOT wsu DOT edu>
Reply-To: phreadd AT powerup DOT com DOT au
NNTP-Posting-Host: ts3406.powerup.com.au
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <Pine DOT OSF DOT 3 DOT 95 DOT 970611151232 DOT 6412A-100000 AT unicorn DOT it DOT wsu DOT edu>, 
jamesj AT wsunix DOT wsu DOT edu says...
>
>I have recently downloaded a copy of djgpp v2.01 and have been using it
>with the rhide IDE.  I have learned how to write and compile basic
>programs but have been working for 3 days on getting my programs to read
>txt files from a dos diretory. 

This will output a text file to the screen, like type.exe:

<-------------------------BEGIN----------------------------->

#include <stdio.h>

main()
{
  FILE *f;
  char ch;

  /* open the file, "rt" means "read, text"       */
  /* if it doesn't work, it might require double  */
  /* slashes. ie. "c://files//sample.txt"         */
  f=fopen("c:/files/sample.txt","rt");

  /* read a char from the file */
  fscanf("%c",&ch);

  /* is it the end of the file yet? */
  while(c!=EOF){

    /* write the char to the screen */
    prinf("%c",ch);

    /* read another character */
    fscanf("%c",&ch);
  }

  /* close the file */
  fclose(f);

  return 0;
}

<------------------------------END-------------------------->

Hope this helps.

-- 
|  David Orme                 <><   |                             |
|  phreadd AT powerup DOT com DOT au           |  "Striving for Excellence"  |
|  powerup.com.au/~phreadd          |                             |

- Raw text -


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