Desafio!

Started by Anonymous, 20 de August , 2006, 11:46:27 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Anonymous

Crie uma função que receba uma string e remova seus ESPAÇOS ' ' essa funcao deve retornar o primeiro caracter da string igual a strstr(char,char); faz ;D

Anonymous

Esta ai sua funcao:

#include
#include

using namespace std;

const char* JumpWhite(char *arg)
{
      std::string r;
      for(int v = 0; v < strlen(arg); v++)
     {
        if( arg[v] != ' ' && arg[v] != '\t' )
        {
           r += arg[v];
        }
     }
     return r.c_str();
}
int main()
{
    char *txt = "Bom dia a todos!";
    char *ret = (char*)JumpWhite(txt);
    cout<< ret ;
    cin.get();
}

Anonymous

Nao intendo de C++ mas pelo q eu testei funfo parabens \o/

Vamos gente mais codigos mais exemplos!

Dark_Side

Hi,
#include <stdio.h>
#include <string.h>
#include <conio.h>

char str[0x64];
void strlol(int inicio,char * str_origem, char * str_destino,int fim);

int main()
{
strlol(0,"Lolz, isto e uma string :)",str,26);
printf(str);
getch();
return 0;
}

void strlol(int inicio,char * str_origem, char * str_destino,int fim)
{
int x,y=0;
for(x = inicio;x<=fim;x++)
if(str_origem[x] != ' '){
str_destino[y] = str_origem[x];
y++;
}
}
Nem sei se era isso, mas gogo.
Bye.

Anonymous

Quote from: "dvd"Crie uma função que receba uma string e remova seus ESPAÇOS ' ' essa funcao deve retornar o primeiro caracter da string igual a strstr(char,char); faz ;D

Tem quer retornar o vetor =L

Anonymous

char* _1337fuck$0x20(unsigned char *string) {
char *p=string;
for(;*string;string++)
if ( *string == ' ' )
strcpy(string,string+1);
return p;
}

Bom essa é a minha funcao \o/ quero ver mais gente vamos exercita o cerebro!

Anonymous

Ve aew....agora deve ta certo:

#include
#include

using namespace std;

const char* JumpWhite(char *arg)
{
      std::string r;
      for(int v = 0; v < strlen(arg); v++)
     {
        if( arg[v] != ' ' && arg[v] != '\t' )
        {
           r += arg[v];
        }
     }
     return r.c_str();
}
int GetFirstWhite(char *arg)
{
   for(int v = 0; v < strlen(arg); v++ )
   {
      if( arg[v] == ' ' || arg[v] == '\t' )
      {
         return v;
      }
   }
   return -1;
}
int main()
{
    char *txt = "Bom dia a todos!";
    char *ret = (char*)JumpWhite(txt);
    cout<< ret << endl ;
   cout<< "Primeiro espaco em branco em: "<< GetFirstWhite(txt) << endl;
    cin.get();
}

Anonymous

Boa mas eu falei espaco ' ' nao \t =L

Anonymous

\t tbm eh um tipo de espaço.........
Agora arrumei os \t.......deve ta certo....

#include
#include

using namespace std;

const char* JumpWhite(char *arg)
{
      std::string r;
      for(int v = 0; v < strlen(arg); v++)
     {
        if( arg[v] != ' ' )
        {
           r += arg[v];
        }
     }
     return r.c_str();
}
int GetFirstWhite(char *arg)
{
   for(int v = 0; v < strlen(arg); v++ )
   {
      if( arg[v] == ' ' )
      {
         return v+1;
      }
   }
   return -1;
}
int main()
{
    char *txt = "Bom dia a todos!";
    char *ret = (char*)JumpWhite(txt);
    cout<< ret << endl ;
   cout<< "Primeiro espaco em branco em: "<< GetFirstWhite(txt) << endl;
    cin.get();
}

Anonymous

Eu percebi que gostaram da ideia xD

anakim

aew gostei do desafio fiz o meu no topico sobre delphi vejam la e tentem resolver T+
Why use Windows? If I have the door ;-)

Anonymous

AAAAAAAAAAAA nao sei nada de delphi  ::)

Anonymous

sim.....soh nao entendi a finalizade da função

Observação: tirem o +1 na função GetFirstWhite()