On Fri, 2003-03-28 at 08:34, Jim Cheetham wrote:
> On Thu, Mar 27, 2003 at 09:51:51PM +1200, Daniel Fone wrote:
> > 
> > int main()
> > {
> >         FILE *myfile;
> >         myfile = fopen("quotes", "r");
> >         if(myfile = NULL)
> >         {
> >                 printf("Quote file not found!");
> >                 return 1;
> >         }
> >         char * sQuote;
> >         fgets(sQuote, 256, myfile);
> >         printf(sQuote);
> >         return 0;
> > }
> > --------------------------------------------------------------
> > 
> > I have no idea what this means and this is the first time I have done any file 
> > I/O in linux. Does anyone know what this means and/or how to fix it?
> 
> You don't have Linux-specific problems, you have C-specific problems.
> C is not always the best thing to use :-) but opinions vary. Under most
> unixes, especially Linux, perl is a useful language for file/data
> manipulations.
> 
> #!/usr/bin/perl -w
> use strict;
> open QUOTE, "quotes" or die "Quote file unreadable!";
> while (<QUOTE>) { print; }
> 
> That's your whole program, with the advantage that you
> re not forced to read and write in 256-byte chunks, and it will
> therefore run faster.
> 
> (Yes, you could change your read buffer size in your C program, and for
> efficiency you'd try to match your system's buffer size ...)
> 
> -jim

Well if you're going to script it you could always bash it out ;)

#!/bin/sh
if [[ -r quotes ]] ; then
        cat quotes
else
        echo "Quotes file unreadable"
fi


Reply via email to