Solved

string

Posted on 1999-01-08
12
202 Views
Last Modified: 2010-04-15
Write a program to remove all the embedded blanks (spaces) given a string
0
Comment
Question by:samuelccs
  • 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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 how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now