954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with delete blank from string function PLEASE!!!!

I need help someone im trying to delete the blanks of this array of strings stored in str[i] 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;
mcole50
Newbie Poster
5 posts since Apr 2007
Reputation Points: 10
Solved Threads: 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++;
}

}
FoX_
Junior Poster in Training
53 posts since Mar 2007
Reputation Points: 10
Solved Threads: 7
 

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]

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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

mcole50
Newbie Poster
5 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You