Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

string

Write a program to remove all the embedded blanks (spaces) given a string
0
samuelccs
Asked:
samuelccs
  • 4
  • 3
  • 3
  • +2
1 Solution
 
scrapdogCommented:
#include <stdio.h>
#include <string.h>

void remove_spaces(char *s) {
int j=0;
for(int i=0;s[i]!=0;i++)
  if(s[i]!=' ') s[j++]=s[i];
s[j]=0;
}

void main() {
char *s="The quick brown fox jumped over the lazy dogs";
remove_spaces(s);
printf(s);
}

0
 
AlexVirochovskyCommented:
Seems as homework! Scrapdog, forbidden of roules!
0
 
scrapdogCommented:
This is a useful function, not necessarily homework.  But after looking at the nature of his other questions, it is obvious that it is homework.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
alexoCommented:
Scrappy, any one liner in the form of "write a program to..." is obviously homework.
0
 
thresher_sharkCommented:
Want me to delete these questions anyone?
0
 
bcnCommented:
I think you want is:

string source:    "    The quick brown fox jumped over the lazy dogs             "

string dst: "The quick brown fox jumped over the lazy dogs"

The function is:

char *Trim(char *str)
{
int     r;
char    *s;

    for(r=strlen(str) - 1; (str[r] == ' ') && (r != 0); r--);

    str[r + 1] = '\0';
   
    s = strdup(str);

    while (*s == ' ')
        *s++;

    strcpy(str,s);

    return str;
}




0
 
alexoCommented:
Clueless newbie.
0
 
scrapdogCommented:
All of us were newbies once...but some of us are clueless forever!
0
 
thresher_sharkCommented:
Hehehe, I can name some clueless forever users... One _starts_ *with* "an" 'O,' !endsĀ” "with" an _a_, and "has" some 't's' in "the" _middle_.  Who is it?
0
 
scrapdogCommented:
more clues please
0
 
alexoCommented:
>> more clues please
An orphan operating system that rhymes with "clue"
0
 
thresher_sharkCommented:
/Yeah/, ...and... "it"--_likes_ BETA 'video' *tapes*!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now