Thread: Basic? C++ open file problem

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    8

    Basic? C++ open file problem

    Hi all,
    I am having trouble with what should be a simple action, opening a file.
    It is a fairly special file with a .uds extension for which I have found a .h include file. I pasted the .h file into a sample program that compiled OK and added the statements below but I still get an error.

    {
    char filestring[50]= "c:\\mscv20\\test\\uds\\edlstn.uds";
    char *ptr ;
    char fileptr = *filestring;
    int fduds ;
    size_t udslen;



    ptr = uds_open_file (fduds,*filestring,udslen);

    The error below

    Initializing...
    Compiling...
    c:\msvc\samples\qwgdemo\qwgdemo.cpp


    c:\msvc\samples\qwgdemo\qwgdemo.cpp(38) : error C2514: 'uds_open_file' : class has no constructors
    CL returned error code 2.
    QWGDEMO.EXE - 2 error(s), 0 warning(s)



    Cheers
    Rick
    Attached Files Attached Files

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    uds_open_file is the name of your struct, not the name of one of your API interfaces for opening a file.

    uds_open_file *uds_open_from_mem (char *mem, size_t len);
    uds_open_file *uds_open (char *filename);
    void uds_close (uds_open_file *file);
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    8
    Salem,
    Thanks for the reply.

    I don't get how to build the statement to actually get the pointer to the open file it's all so cryptic (it is 20 years since I programmed on C) and I was only dealing with a basic ascii text file.
    I tried
    char filestring[50]= "c:\\mscv20\\test\\uds\\edlstn.uds";
    char *ptr ;
    char fileptr = *filestring;




    fileptr = uds_open(*filestring);


    Compiling...
    c:\msvc\samples\qwgdemo\qwgdemo.cpp
    c:\msvc\samples\qwgdemo\qwgdemo.cpp(151) : error C2664: 'uds_open' : cannot convert parameter 1 from 'char ' to 'char __near *'
    CL returned error code 2.
    QWGDEMO.EXE - 1 error(s), 0 warning(s)




    and.....




    char filestring[50]= "c:\\mscv20\\test\\uds\\edlstn.uds";
    char *ptr ;
    char fileptr = *filestring;




    fileptr = uds_open(filestring);




    Compiling...
    c:\msvc\samples\qwgdemo\qwgdemo.cpp
    c:\msvc\samples\qwgdemo\qwgdemo.cpp(150) : error C2446: '=' : no conversion from 'struct ::uds_open_file_t __near *' to 'char '
    CL returned error code 2.
    QWGDEMO.EXE - 1 error(s), 0 warning(s)

    I am not understanding how to construct this statement and why it needs to be a particular way.

    Cheers
    Rick

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Code:
    char myfile[] = "c:\\test.uds";
    
    uds_open_file* file = uds_open(myfile);
    May I ask what compiler you are using? Any piece of software that is talking about near or far pointers is probably from the last millenium and should be replaced. A modern compiler probably would allow the following:

    Code:
    auto myfile = "c:\\test.uds";
    
    auto file = uds_open(myfile);
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Why not just
    auto file = uds_open("c:\\test.uds");
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Jan 2012
    Posts
    8
    Thanks for the reply mr Voigt.

    Microsoft Visual C++ version 1.5. My Visual C++ also has Version 2 but that had many more difficulties. V 1.5 comes the closest to3actually working.

    I am compiling on a windows XP laptop vintage 2003 - I do have a Windows ME pc I can try if this is necessary.

    Cheers
    Rick

  7. #7
    Registered User
    Join Date
    Jan 2012
    Posts
    8
    Thanks for the reply,
    I just tried that and received the following error.
    I used you exact statement but substituted the file I am trying to open.

    auto file = uds_open("c:\\test.uds");


    Compiling...
    c:\msvc\samples\qwgdemo\qwgdemo.cpp
    c:\msvc\samples\qwgdemo\qwgdemo.cpp(150) : error C2440: 'initializing' : cannot convert from 'struct ::uds_open_file_t __near *' to 'int '
    CL returned error code 2.
    QWGDEMO.EXE - 1 error(s), 0 warning(s)

    Cheers
    Rick

  8. #8
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Microsoft Visual C++ version 1.5


    Hie thee to Visual C++ 2010 Express | Microsoft Visual Studio and download the latest free MS C++ compiler. And no...don't go back to the abomination that is Windows ME.

  9. #9
    Registered User
    Join Date
    Jan 2012
    Posts
    8
    The file I am trying to open is from Generations family tree, a program going back to Win 95 days. I am not sure if I have a PC with win 98 still loaded. Maybe.
    My concern has been do I need to run an OS on FAT16 for this to compile and open the file properly?
    And if I use a compiler much more recent, will it be compatible with the files which are in an old program.

    I am not even certain at this stage if Christopher P's UDS.H file is of the right shape and structure for Generations or if its for something else.


    Cheers
    Rick

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If Windows supports reading and writing files on a FAT16 partition (Why the hell do you have such a partition still in existence? Get rid of it!), then any modern compiler will be fine.
    For the sake of the world, get rid of Windows 98!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Jan 2012
    Posts
    8
    I am currently running Windows 7, the compiler I have does not work with this. In order to find a PC that the compiler would load into, I had to dig out an older one. So no, I dont currently use a Win 98 PC, I am trying to work out what I am doing wrong to get these errors.

    Cheers Rick

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Upgrade compiler?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    Jan 2012
    Posts
    8
    Hi and thanks,
    I downloaded the new compiler Vis C++ express as suggested onto my main PC which runs Win 7 ultimate.

    With just the uds include file and stdafx.h added to the cpp file I get a string of errors ...
    1>------ Build started: Project: FixUDS, Configuration: Debug Win32 ------
    1> FixUDS.cpp
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(10): error C2059: syntax error : 'constant'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(10): error C2014: preprocessor command must start as first nonwhite space
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(11): error C2014: preprocessor command must start as first nonwhite space
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(16): error C2041: illegal digit '8' for base '8'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(16): error C2014: preprocessor command must start as first nonwhite space
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(17): error C2041: illegal digit '9' for base '8'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(17): error C2014: preprocessor command must start as first nonwhite space
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(18): error C2014: preprocessor command must start as first nonwhite space
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(20): error C2014: preprocessor command must start as first nonwhite space
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(21): error C2014: preprocessor command must start as first nonwhite space
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(22): error C2014: preprocessor command must start as first nonwhite space
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(23): error C2014: preprocessor command must start as first nonwhite space
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(24): error C2014: preprocessor command must start as first nonwhite space
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(27): error C2143: syntax error : missing ';' before '{'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(27): error C2447: '{' : missing function header (old-style formal list?)
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(43): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(44): error C2041: illegal digit '8' for base '8'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(44): error C2059: syntax error : 'constant'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(45): error C2041: illegal digit '9' for base '8'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(46): error C2041: illegal digit '8' for base '8'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(47): error C2041: illegal digit '8' for base '8'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(47): error C2143: syntax error : missing ';' before '{'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(47): error C2447: '{' : missing function header (old-style formal list?)
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(48): error C2041: illegal digit '8' for base '8'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(49): error C2041: illegal digit '8' for base '8'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(49): error C2041: illegal digit '8' for base '8'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(50): error C2041: illegal digit '8' for base '8'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(50): error C2041: illegal digit '9' for base '8'
    1>c:\fixuds\fixuds\fixuds\uds_lowlevel.h(51): error C2041: illegal digit '9' for base '8'

    These all appear to come from the uds_lowlevel.h - if I put this before stdafx.h but if I position this .h file after stdafx.h then it is ignored.

    It's so hard to get started, particularly with the non standard file structure I m attempting to work with.
    Perhaps I need more .h files?

    Cheers
    Rick

  14. #14
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Those errors about illegal digits point to some pretty serious mistakes in the original code.
    You much have a bunch of constants in the program that start with a zero that are not meant to start with a zero.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  15. #15
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Can you point us to where you got this uds_lowlevel.h file, or maybe post the exact file here? The line numbers in the error messages do not line up with I can find.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem with open file.
    By oror84 in forum C Programming
    Replies: 5
    Last Post: 01-15-2011, 08:19 AM
  2. Replies: 3
    Last Post: 03-08-2010, 02:43 PM
  3. basic file handling problem
    By georgen1 in forum C Programming
    Replies: 4
    Last Post: 03-05-2009, 06:21 AM
  4. Open File/Save File crashes on cancel?
    By Blackroot in forum Windows Programming
    Replies: 0
    Last Post: 08-02-2008, 02:16 AM
  5. Replies: 12
    Last Post: 03-10-2005, 07:48 PM