Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

string

Posted on 1999-01-08
12
Medium Priority
?
211 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
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.

 
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 60 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

Industry Leaders: 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!

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

715 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