|
-
Oct 7th, 2001, 07:33 AM
#1
Thread Starter
transcendental analytic
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.
-
Oct 7th, 2001, 10:45 AM
#2
Hyperactive Member
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.
-
Oct 7th, 2001, 11:38 AM
#3
Thread Starter
transcendental analytic
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.
-
Oct 8th, 2001, 11:50 AM
#4
Hyperactive Member
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 *str, int 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.
-
Oct 8th, 2001, 12:08 PM
#5
Thread Starter
transcendental analytic
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.
-
Oct 8th, 2001, 12:37 PM
#6
Hyperactive Member
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.
-
Oct 8th, 2001, 01:14 PM
#7
Thread Starter
transcendental analytic
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.
-
Oct 8th, 2001, 01:29 PM
#8
Hyperactive Member
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.
-
Oct 8th, 2001, 03:05 PM
#9
Thread Starter
transcendental analytic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|