Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 10-25-2004, 11:35 AM   #1 (permalink)
mike_cana
Registered User
 
Join Date: Oct 2004
Posts: 2
mike_cana is on a distinguished road
using correct path in open function

Hi everyon, I need to open a file, and if it doesn't exist, make a new one wieth a long value as its name. I found that I can use the Open() function, but I'm having problems with using the correct path.
I want to put the new file or access it from DIR_BANK, and add the SUF_BANK extension to it; both of which are declared in a helper file.
Here is a part of my code, when I try to execute my program, I get the following error: "No such file or directory"
Can you please help me out?
I have commented out all the different paths I tried!
Thanks in advance,
Mike
Code:
int openOrCreateAcct (int * const acctFd, const unsigned long acctNum)
{  
  int fd;
  // const char *path = '"%s%u%s", DIR_BANK, acctNum, SUF_BANK';
  //const char *path = "bankPro/acctNum.cct";
  //const char *path = "DIR_BANK/acctNum.SUF_BANK"; //want this!

  if (*acctFd = (fd = open(path, "O_CREAT", "r+")) < 0)
  {
      *acctFd = -1;
      perror("Open failed");
      exit(2);
   }
 .
 .
 .
mike_cana is offline   Reply With Quote
Old 10-25-2004, 04:15 PM   #2 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
Re: using correct path in open function

Quote:
Originally posted by mike_cana
Code:
  if (*acctFd = (fd = open(path, "O_CREAT", "r+")) < 0)
your second and third arguments to open(2) are garbage. O_CREAT is a defined value, not a string literal. include the following headers if you haven't done so already, and it will be defined for you.

Code:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
the 3 argument version of open takes a numerical value which defines the mode bits of the file you want created. there are convenient defines for this one as well.

Code:
open(path, O_CREAT, S_IRUSR | S_IWUSR);
try "man 2 open" for more details.
joe_bruin is offline   Reply With Quote
Old 10-25-2004, 06:06 PM   #3 (permalink)
mike_cana
Registered User
 
Join Date: Oct 2004
Posts: 2
mike_cana is on a distinguished road
thanks
I'm still noob programmer ( I find Java to be so much easier )

ok, now how do I set the path to "DIR_BANK/acctNum.SUF_BANK"
where DIR_BANK and SUF_BANK are defined in a helper file, and acctNum is passed in as a parameter?
mike_cana is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting the path for python scripting Intensegutwound All Other Coding Languages 7 11-23-2004 06:32 AM
Open Source by Osmosis revolution Code Newbie News 0 08-10-2003 05:36 PM
dynamic allocation..urgent help needed!!! kashif Standard C, C++ 4 04-21-2003 08:50 AM
pass filename to function Blaqb0x Standard C, C++ 1 09-02-2002 10:12 PM


All times are GMT -8. The time now is 05:40 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting