English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

c programming

2006-10-12 05:49:30 · 4 answers · asked by Ricky 2 in Computers & Internet Programming & Design

4 answers

check out Planet Source Code. http://www.pscode.com - you can search for "string manipulation" and restrict your result set to just C results.

2006-10-12 05:57:22 · answer #1 · answered by Richard H 7 · 1 0

You construct another string with the blank spaces removed...

I haven't done C in a while but it could be something like this...(my syntax is probably off depending on the version of C compiler you are using)
int n = strlen(oldString);
int c = 0;
char newString[n+1];
for(int x = 0; x < n; x++)
{

if (oldString[x]!=' ')
{
newString[c] = oldString[x];
c++;
}

}
newString[c] = '\0';


Something like the above anyway, I'm treating both strings as simple char arrays, and the new string has some wasted space at the end... this could be fixed by recopying it over again possibly using another str function.

2006-10-12 06:04:28 · answer #2 · answered by boris 5 · 0 0

use trim() in java this removes the blank places

2006-10-12 05:59:35 · answer #3 · answered by doubt G 1 · 1 0

Here's a simple function for you to use.

#include

// parameters:
// c: pointer to the string
// what it does:
// removes all whitespace in c,
// assumes c points at a null terminated string
void remove_whitespace(char *c)
{
. . . . char *write = c;
. . . . char *read = c;
. . . . for(; *read != '\0'; read++)
. . . . {
. . . . . . . . if(!isspace(*read))
. . . . . . . . {
. . . . . . . . . . . . *write++ = *read;
. . . . . . . . }
. . . . }
. . . . *write = '\0';
}

2006-10-12 06:33:06 · answer #4 · answered by shap411233 2 · 2 0

fedest.com, questions and answers