NO

Author Topic: creating simple text files  (Read 3890 times)

grom-it

  • Guest
creating simple text files
« on: August 07, 2007, 11:32:38 AM »
static void OpenFiles(char filname[],int opt)
{

   if (opt==1)
            
      g_inputfilepointer= fopen(filname, "w");
           
   if (opt==2)
      g_inputfilepointer= fopen(filname, "r");


}

Program compiles ok but using the following call my error message is triggered

   OpenFiles,( L"Location",1);
      if (g_inputfilepointer==NULL)
      {
      MessageBox(g_hwnd, L"Could not open Location
      File.", L"Error", MB_OK | MB_ICONERROR);
                   }
   
g_inputfilepointer is a global file pointer
Any advice as to where i am going wrong would be great

I have searched around a bit and read something that seemed to say that i had to declare the full path??
BTIA grom-it

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: creating simple text files
« Reply #1 on: August 07, 2007, 12:33:58 PM »
You should use the widechar version of fopen:
Code: [Select]
static void OpenFiles(wchar filname[],int opt)
{
   if (opt==1)
      g_inputfilepointer= _wfopen(filname, L"w");
           
   if (opt==2)
      g_inputfilepointer= _wfopen(filname, L"r");
}
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

grom-it

  • Guest
Re: creating simple text files
« Reply #2 on: August 07, 2007, 11:30:34 PM »
Thanks Frankie but i could not get one created  let alone opened

using wchar_t
as in
static void OpenFiles(wchar_t filname[],int opt)
{

i am still triggering file not opened message
i have even tried a full path
using
     HINSTANCE hInstance = GetModuleHandle(NULL);
    wchar_t szFileName[MAX_PATH];
        GetModuleFileName(hInstance,szFileName, MAX_PATH);
Still no joy

Is this something to do with WM5 ?????

should i use createfile structure in win32 API ??????

any further advice would be useful...
BTIA  grom-it

grom-it

  • Guest
Re: creating simple text files
« Reply #3 on: August 09, 2007, 09:49:38 PM »
I am going to answer my own question here

just to bring this thread to an end

The reason i could not get a file pointer was because of this line here in my original question

OpenFiles,( L"Location",1);

notice the comma after the openFiles call

left in it compiles but does not work

left out and i get a file pointer
 ;D :D :D :D


Thanks for your help on the wchar aspect frankie
It does look like my original guff was a typo............