CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21

Thread: String problems

  1. #16
    Join Date
    Apr 1999
    Posts
    27,449

    Re: String problems

    Quote Originally Posted by chibicitiberiu View Post
    Than how do I do that? I don't really know how to allocate memory, i know very few information about pointers.
    How do I know how much memory will this string need?
    You assumed that you did know how much memory by doing this:
    Code:
    for (i=lastslash;i<=strlen(pat);i++)
    	filename[i-lastslash]=pat[i];
    So how big were you expecting the filename string to be in the code above? Whatever that is, you need to create or have access to a buffer of that size first before this code is invoked.

    Once you know that, then you use new[] and delete[] to allocate and deallocate memory. But as JohnW pointed out, it would be much worth your while to write a string class and use that instead. But that requires you know how to use dynamic allocation (new[]/delete[]).

    Regards,

    Paul McKenzie

  2. #17
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: String problems

    Try this updated simple string class (with demo).
    It should supply most of your needs.
    Attached Files Attached Files
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  3. #18
    Join Date
    Jan 2009
    Posts
    25

    Re: String problems

    Quote Originally Posted by JohnW@Wessex View Post
    Try this updated simple string class (with demo).
    It should supply most of your needs.
    Thanks, but this doesn't work in my compiler, it says "Syntax error" at the lines where is declared "bool ...".

    Now I have a question... will console programs made in MS Visual Studio (2005) work on MS-DOS machines? Because I see that this old compiler is good for trash...

  4. #19
    Join Date
    Apr 1999
    Posts
    27,449

    Re: String problems

    Quote Originally Posted by chibicitiberiu View Post
    Thanks, but this doesn't work in my compiler, it says "Syntax error" at the lines where is declared "bool ...".
    A "bool" is a C++ type denoting values true or false. This shows that your compiler is so old, it is practically worthless. Change the "bool" to int if you have to, and wherever you see "false" being assigned to it, replace it with 0, and if "true", replace with 1.
    Now I have a question... will console programs made in MS Visual Studio (2005) work on MS-DOS machines? Because I see that this old compiler is good for trash...
    No. MS-DOS is a 16-bit OS, and Visual Studio 2005 makes 32-bit programs.

    You could get a better compiler for 16-bit DOS here:

    www.digitalmars.com

    Regards,

    Paul McKenzie

  5. #20
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: String problems

    Quote Originally Posted by chibicitiberiu View Post
    Thanks, but this doesn't work in my compiler, it says "Syntax error" at the lines where is declared "bool ...".
    Microsoft defined TRUE, FALSE & BOOL before 'bool' was part of the standard. You could do something similar.

    const int TRUE = 1;
    const int FALSE = 0;
    typedef int BOOL;
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  6. #21
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: String problems

    Quote Originally Posted by Paul McKenzie View Post
    You could get a better compiler for 16-bit DOS here:
    www.digitalmars.com
    That looks like a good option. It appears to support the STL too.
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured