Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.mac.programmer.help > #135

Re: fopen problem - straight C program on OS Lion, Xcode 4.3.2 - whazzup?

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From "kquirici@yahoo.com" <kquirici@yahoo.com>
Newsgroups comp.sys.mac.programmer.help
Subject Re: fopen problem - straight C program on OS Lion, Xcode 4.3.2 - whazzup?
Date Sun, 17 Jun 2012 08:38:08 -0700 (PDT)
Organization http://groups.google.com
Lines 80
Message-ID <ee3750bb-dbf1-411e-b772-34be0c45824f@googlegroups.com> (permalink)
References <a05151a5-ea7c-479c-9f08-9e3c147be254@googlegroups.com> <87oboiq8b0.fsf@araminta.anjou.terraraq.org.uk>
NNTP-Posting-Host 74.104.157.148
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
X-Trace posting.google.com 1339947489 4127 127.0.0.1 (17 Jun 2012 15:38:09 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Sun, 17 Jun 2012 15:38:09 +0000 (UTC)
In-Reply-To <87oboiq8b0.fsf@araminta.anjou.terraraq.org.uk>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=74.104.157.148; posting-account=NBUN0woAAAAnKUwZeEs32wbbmpbmo_jZ
User-Agent G2/1.0
X-Received-Bytes 3255
Xref csiph.com comp.sys.mac.programmer.help:135

Show key headers only | View raw


On Sunday, June 17, 2012 11:14:59 AM UTC-4, Richard Kettlewell wrote:
> "kquirici@yahoo.com" <kquirici@yahoo.com> writes:
> 
> > A skeleton program which is supposed to open a text file (created by
> > Wrangler so it's unicode but w/ unix lf breaks) and read a line and print it.
> > he file exists in the location as specified in the code,
> > which is below. The build succeeded w/o error. It's prob. some stupid typo
> > but I can't see it.
> >
> > Regards,
> >
> > ken quirici
> >
> > here's the output returned:
> >
> > fopen failed
> > my_ret = -1
> >
> > Here's the code as copied from the Xcode editor.
> >
> > //
> > //  main.c
> > //  encode
> > //
> > //  Created by ken quirici on 6/16/12.
> > //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
> > //
> >
> > #include <stdio.h>
> >
> > int main(int argc, const char * argv[])
> > {
> >     char *my_filename;
> >     char *my_mode;
> >     char next_line[1000000];
> >     int my_ret,max_line;
> >     
> >     my_filename = "/Users/kenquirici/Desktop/journal/journal.txt.save";
> >     my_mode = "r";
> >     max_line = 1000000;
> > //    next_line = "";
> > //    my_ret_line = "";
> >     
> >     FILE *my_file;
> >     
> >     if((my_file = fopen(my_filename,my_mode)) == NULL)
> >         printf("fopen failed\n");
> 
> Use perror() instead of printf, so you can see why the file couldn't be
> opened, e.g.:
> 
>   perror(my_filename);
> 
> >     else if(fgets(next_line,max_line,my_file) == NULL)
> >        printf("fgets returned null\n");
> >     else
> >        printf("%s%s","next_line: ",next_line);
> 
> That's a really bizarre way to use printf.  Why not:
> 
>   printf("next_line: %s", next_line);
> 
> >     my_ret = fclose(my_file);
> 
> Calling fclose() on a null pointer (as you do in the error case) is a
> bug.
> 
> >     // insert code here...
> >     printf("%s%d%s","my_ret = ",my_ret,"\n");
> >     return 0;
> > }
> 
> -- 
> http://www.greenend.org.uk/rjk/

ok I'll try perror. Thx for that & the other suggestions.

Regards

ken quirici

Back to comp.sys.mac.programmer.help | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

fopen problem - straight C program on OS Lion, Xcode 4.3.2 - whazzup? "kquirici@yahoo.com" <kquirici@yahoo.com> - 2012-06-17 07:55 -0700
  Re: fopen problem - straight C program on OS Lion, Xcode 4.3.2 - whazzup? Richard Kettlewell <rjk@greenend.org.uk> - 2012-06-17 16:14 +0100
    Re: fopen problem - straight C program on OS Lion, Xcode 4.3.2 - whazzup? "kquirici@yahoo.com" <kquirici@yahoo.com> - 2012-06-17 08:38 -0700
    Re: fopen problem - straight C program on OS Lion, Xcode 4.3.2 - whazzup? "kquirici@yahoo.com" <kquirici@yahoo.com> - 2012-06-17 08:54 -0700
    Re: fopen problem - straight C program on OS Lion, Xcode 4.3.2 - whazzup? "kquirici@yahoo.com" <kquirici@yahoo.com> - 2012-06-17 08:53 -0700
      Re: fopen problem - straight C program on OS Lion, Xcode 4.3.2 - whazzup? Richard Kettlewell <rjk@greenend.org.uk> - 2012-06-17 18:00 +0100
        Re: fopen problem - straight C program on OS Lion, Xcode 4.3.2 - whazzup? "kquirici@yahoo.com" <kquirici@yahoo.com> - 2012-06-17 13:12 -0700
      Re: fopen problem - straight C program on OS Lion, Xcode 4.3.2 - whazzup? Bob Harris <nospam.News.Bob@remove.Smith-Harris.us> - 2012-06-18 22:30 -0400

csiph-web