Topic
  • 2 replies
  • Latest Post - ‏2012-11-21T04:11:01Z by scott_klement
SystemAdmin
SystemAdmin
102 Posts

Pinned topic problems opening a text file in c

‏2012-11-20T12:54:00Z |
Hi,
I wrote a C program that modifies a text file. It works fine when compiled in Windows (using MinGW compiler), but when I compile and run the program from the iSeries, I receive this error on the fopen() function: The object name specified is not correct.

I have the file in both my home directory (/home/cjdelatte) and root directory. Both files have a CCSID of 1252. I can see them using Navigator, WRKLNK and STRQSH. Their type is STMF.

The files are in 2 places because I wasn’t sure if the default location was my home directory or the root directory. In my desperation, I have coded this, hoping the program would open the file in either location:


fp = fopen(
"hubmiles.txt",
"rb"); 

if (!fp) 
{ fp = fopen(
"/hubmiles.txt",
"rb"); 

if (!fp) 
{ fp = fopen(
"/home/cjdelatte/hubmiles.txt",
"rb"); 

if (!fp) 
{ fp = fopen(
"/home/CJDELATTE/hubmiles.txt",
"rb"); 

if (!fp) 
{ perror(
"Just cant do it! "); 

return -1; 
} 
} 
} 
}


I also tried the same thing with open modes of “r” and “r+” and compiled the module specifying both *IFSIO and *NOIFSIO. Even if specify a file that doesn’t exist and change the open mode to “a”, I get the same error. I have no problems opening this file using an RPGILE program so I’m wondering if my issue is a flag that needs to be set or a compile option that I’m missing?

Can anyone offer a suggestion?
Updated on 2012-11-21T04:11:01Z at 2012-11-21T04:11:01Z by scott_klement
  • SystemAdmin
    SystemAdmin
    102 Posts

    Re: problems opening a text file in c

    ‏2012-11-20T21:22:28Z  
    I figured out what the issue was. I needed to specify *IFSIO on both the create module and create program commands.
  • scott_klement
    scott_klement
    31 Posts

    Re: problems opening a text file in c

    ‏2012-11-21T04:11:01Z  
    I figured out what the issue was. I needed to specify *IFSIO on both the create module and create program commands.
    Glad you figured it out.

    But, yeah.. by default fopen() is tryign to open a physical file in a library. When you specify SYSIFCOPT(*IFSIO), it changes it to use the IFS interface and open a stream file, instead.