• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • 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
Protect Your Employees from Wi-Fi Threats

As Wi-Fi growth and popularity continues to climb, not everyone understands the risks that come with connecting to public Wi-Fi or even offering Wi-Fi to employees, visitors and guests. Download the resource kit to make sure your safe wherever business takes you!

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

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