Array problem
Hi guys,
I was just wondering if a char array conatains "testing 123" and you want to remove the space between the testing and 123 how would you do this and what if there is more than one space between the testing and 123?
I have already got the code so it stops when it finds the g in testing but after that im not sure what to do. Thanks.
[358 byte] By [
C++ Angel] at [2007-11-11 8:03:55]

# 1 Re: Array problem
try something like this...
char str[] = "testing 123";
char *newStr = (char *)malloc(sizeof(char) * strlen(str));
for(int x = 0, y = 0; x < strlen(str); x++, y++)
{
if(str[x] == ' ')
{
y--;
continue;
}
newStr[y] = str[x];
}
newStr[y] = '\0';
printf("%s\n%s\n", str, newStr);
x is this current position in str, y is the current position in newStr
add null char at end (newStr[y] = '\0')
hope this helps
Note: this also works if there is more than one space
# 3 Re: Array problem
anyone know how 2 make sinusoidal graph using borland C++ builder.
the input is maximum value of Y-axis. can ignore the X-axis value.,
wary83 at 2007-11-11 21:03:39 >
