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;
Printable View
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;
kedaman..thanks..
but lets say i do this
it overwrites whats in the buf string...Code:
char buf[10] = "boom";
cout << (char *)memset(buf + 1, ' ', 3) << endl;
this would give me "b "...maybe i am wrong and that's what space does?
nope, youre correct, you get "b" and 3 spaces.
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??
thanksPHP 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;
}
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?
ok, i am sorry to bother you guys with stupid questions..
i tried to put it into c++ like this: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
after i was finished writing it , i thought: What the hell am i doing!!!..PHP Code:char *occur;
occur = strstr(value, '\0');
while (!(occur == 0)) {
value = _left(value, (occur - 1)) & _mid(value, (occur + 1));
occur = strstr(value, '\0');
}
could one of you guys please help me..thanks a lot..
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?
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
in C++? thanks again..=)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))
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.