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


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

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

From "kquirici@yahoo.com" <kquirici@yahoo.com>
Newsgroups comp.sys.mac.programmer.help
Subject fopen problem - straight C program on OS Lion, Xcode 4.3.2 - whazzup?
Date 2012-06-17 07:55 -0700
Organization http://groups.google.com
Message-ID <a05151a5-ea7c-479c-9f08-9e3c147be254@googlegroups.com> (permalink)

Show all headers | View raw


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");
    else if(fgets(next_line,max_line,my_file) == NULL)
       printf("fgets returned null\n");
    else
       printf("%s%s","next_line: ",next_line);
    
    my_ret = fclose(my_file);

    // insert code here...
    printf("%s%d%s","my_ret = ",my_ret,"\n");
    return 0;
}


Back to comp.sys.mac.programmer.help | Previous | NextNext 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