Results 1 to 9 of 9

Thread: space

  1. #1

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    you can use memset() to fill something with any character

    this will for instance put 3 spaces into "Something" starting at 2'nd character (buf[1])
    PHP Code:
        char buf[10]="Something";
        
    cout << (char*)memset(buf+1,' ',3)-1
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  2. #2
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    kedaman..thanks..
    but lets say i do this

    Code:
    char buf[10]  = "boom";
    cout << (char *)memset(buf + 1, ' ', 3) << endl;
    it overwrites whats in the buf string...
    this would give me "b "...maybe i am wrong and that's what space does?
    Amon Ra
    The Power of Learning.

  3. #3

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    nope, youre correct, you get "b" and 3 spaces.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  4. #4
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    lets say in my space function, the user gives a number of spaces to put in that is bigger than the number of char's in the char *..i have a condition statement checking for that, but if the function returns a char *, how would i break out of the function??

    PHP Code:
    char *_space(char *strint sz)
    {
        
    char *buf;
        if ((
    sz 0) || (sz abs(strlen(str))))
            return 
    '\0';
        
    buf strdup(str);
        
    buf = (char *)memset(buf' 'sz);
            return 
    buf;

    thanks
    Amon Ra
    The Power of Learning.

  5. #5

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Your string functions shouldn't be responsible for checking the lenght, you might as well have buffer left over and the termination null is halfway on it. Why not use memset directly?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  6. #6
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    ok, i am sorry to bother you guys with stupid questions..

    PHP Code:
    Dim iPos As Integer
        
    ' Strip chr$(0):
        iPos = InStr(sValue, Chr$(0))
        Do While iPos <> 0
            sValue = Left$(sValue, (iPos - 1)) & Mid$(sValue, (iPos + 1))
            iPos = InStr(sValue, Chr$(0))
        Loop 
    i tried to put it into c++ like this:

    PHP Code:
        char *occur;
        
    occur strstr(value'\0');
        while (!(
    occur == 0))    {
            
    value _left(value, (occur 1)) & _mid(value, (occur 1));
            
    occur strstr(value'\0');
        } 
    after i was finished writing it , i thought: What the hell am i doing!!!..
    could one of you guys please help me..thanks a lot..
    Amon Ra
    The Power of Learning.

  7. #7

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You want to strip off the nullchars? That wouldn't be too good since C strings are nullterminated, or do you want to strip a fixed length string of nullchars?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500
    the function is basically to get a value in an INI file..so i suppose i dont actually need to worry about nullchars, right?
    however, could you plese quickly try to giveme an equivalent to

    PHP Code:

    Dim iPos 
    As Integer
        
    ' Strip chr$(0):
        iPos = InStr(sValue, Chr$(0))
        Do While iPos <> 0
            sValue = Left$(sValue, (iPos - 1)) & Mid$(sValue, (iPos + 1))
            iPos = InStr(sValue, Chr$(0)) 
    in C++? thanks again..=)
    Amon Ra
    The Power of Learning.

  9. #9

    Thread Starter
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Not unless it's nessesary, I don't get why you search for nulls in a ini file. char arrays without terminating nullchars aren't C strings, which means they won't be compatible with the C string functions.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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