0

I need help someone im trying to delete the blanks of this array of strings stored in str loop but cant copy wihtout delete spaces please help some one.. thanks

void deblank(char str[MAX_STR], char result[MAX_STR])
{
 
int num; //variable to hold value for string length
int i, j; // loop control variable
// strcpy(result,str);
num = strlen(str);
for(i=0 ;i<=num; i++) // loop to store vaules in array
 
for(j=0; j<=num; j++)
{
if (str[i] != ' ')
 
result[j]= str[i];
}
 
 
 
return;
3
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by mcole50
0

It isn't neccessary a nested loop.You can do it with one loop like the following code...(Assume that j = 0 at starting)

for(i=0 ;i<=num; i++) // loop to store values in array
{

if (str[i] != ' '){
result[j]= str[i];
j++;
}

}
0

you don't need the j loop. Just delete line 10 and increment it in line 14. Don't forget to initialize j in line 5.

[edit]Just like Fox showed[/edit]

0

omg thank u so much i was stuck on this for like weeks im kinda new to c programming so im still learning i really appreciate the help so much your an life saver

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.