Solved

string

Posted on 1999-01-08
12
210 Views
Last Modified: 2010-04-15
Write a program to remove all the embedded blanks (spaces) given a string
0
Comment
Question by:samuelccs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +2
12 Comments
 
LVL 5

Expert Comment

by:scrapdog
ID: 1255616
#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
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 1255617
Seems as homework! Scrapdog, forbidden of roules!
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1255618
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
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 11

Expert Comment

by:alexo
ID: 1255619
Scrappy, any one liner in the form of "write a program to..." is obviously homework.
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1255620
Want me to delete these questions anyone?
0
 

Accepted Solution

by:
bcn earned 20 total points
ID: 1255621
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
 
LVL 11

Expert Comment

by:alexo
ID: 1255622
Clueless newbie.
0
 
LVL 5

Expert Comment

by:scrapdog
ID: 1255623
All of us were newbies once...but some of us are clueless forever!
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1255624
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
 
LVL 5

Expert Comment

by:scrapdog
ID: 1255625
more clues please
0
 
LVL 11

Expert Comment

by:alexo
ID: 1255626
>> more clues please
An orphan operating system that rhymes with "clue"
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1255627
/Yeah/, ...and... "it"--_likes_ BETA 'video' *tapes*!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question