Eliminar espaço em branco nas variaveis

Software e Hardware para uC PIC

Moderadores: andre_luis, 51, guest2003, Renie

Eliminar espaço em branco nas variaveis

Mensagempor Alvarosan » 01 Out 2014 15:50

Olá pessoal, necessito mais uma vez a ajuda do pessoal do forum, utilizo o compilador MikroC, e preciso enviar para um display gráfico o valor de algumas variaveis, estou utilizando o comando IntToStr para converter int para str, porém quando envio um valor ex. "346", aparece no display " 346", ou seja um espaço antes do valor, como faço para eliminar esse espaço em branco e imprimir somente os valores válidos, segue abaixo uma parte do programa, obrigado.

cpp code
void processo(){

unsigned int x_coord, y_coord;
int tecla = 255;
int valor[4] ;
int i = 0;
int col_x = 0;
int lin_y = 0;
int total = 0;

char txt[4];

int coluna = 14;
int linha = 5;
int PulsoMotor = 0;

xGlcd_Set_Font(Times_New_Roman16x16, 16,16,32);

xGlcd_Write_Text("START",coluna+24, linha+10,xColorSet);
xGlcd_Write_Text("STOP",coluna+31, linha+40,xColorSet);
xGlcd_Set_Font(Times_New_Roman11x12, 11,12,32);

Glcd_Rectangle_Round_Edges(coluna+10, linha+7, coluna+90, linha+25, 3, 1);
Glcd_Rectangle_Round_Edges(coluna+10, linha+37, coluna+90, linha+55, 3, 1);
while(1){
if (TP_Get_Coordinates(&x_coord, &y_coord) == 0){
if ((x_coord > coluna+10) && (x_coord < coluna+90) && // tecla start
(y_coord > linha+10) && (y_coord < linha+20)){
Glcd_Box(coluna+12, linha+9, coluna+88, linha+23,2);
Sound_Play(2000, 50);
Glcd_Box(coluna+12, linha+9, coluna+88, linha+23,2);
Glcd_Fill(0); // Clear GLCD

xGlcd_Set_Font(Times_New_Roman14x13, 14,13,32);

total=EepromRead16(0x02); //by alvaro.h
IntToStr(total,txt); // converte de INT para STR
xGlcd_Write_Text(txt, 35,0,xColorSet);
xGlcd_Write_Text("Compr.:", 1, 0,xColorSet);
xGlcd_Write_Text("/", 85, 0,xColorSet);

PulsoMotor = total;
while(PulsoMotor > 0){
if (!RE0_bit){
PulsoMotor--;
xGlcd_write_text(txt, 35,0,xColorClear); // delete the written text
IntToStr(PulsoMotor,txt);
xGlcd_Write_Text(txt, 35,0,xColorSet);
while(!RE0_bit);
}
}
RA3_bit = 1;
sound_Play(2000,500);
while (RE2_bit);
sound_Play(1000,500);
RA3_bit = 0;
}
if ((x_coord > coluna+10) && (x_coord < coluna+90) && // tecla stop
(y_coord > linha+40) && (y_coord < linha+53)){
Glcd_Box(coluna+12, linha+39, coluna+88, linha+53,2);
Sound_Play(2000, 50);
Glcd_Box(coluna+12, linha+39, coluna+88, linha+53,2);
break;
}
}
}
} // End void Processo()
Alvarosan
Bit
 
Mensagens: 20
Registrado em: 14 Out 2006 10:55
Localização: Ribeirao Preto

Re: Eliminar espaço em branco nas variaveis

Mensagempor tcpipchip » 01 Out 2014 19:02

char *res;

res = Ltrim(" TCPIPCHIP");

RES vai ter "TCPIPCHIP"
------------------------------------------
http://www.youtube.com/tcpipchip
Avatar do usuário
tcpipchip
Dword
 
Mensagens: 6560
Registrado em: 11 Out 2006 22:32
Localização: TCPIPCHIPizinho!

Re: Eliminar espaço em branco nas variaveis

Mensagempor Alvarosan » 01 Out 2014 19:15

Perfeito, deu certo, muito obrigado pela dica, tcpipchip.
um abraço.
alvarosan@ig.com.br
Alvarosan
Bit
 
Mensagens: 20
Registrado em: 14 Out 2006 10:55
Localização: Ribeirao Preto

Re: Eliminar espaço em branco nas variaveis

Mensagempor barboza » 03 Out 2014 08:21

Conforme o manual do mikroc:

http://www.mikroe.com/download/eng/docu ... m#inttostr

Converts input signed integer number to a string. The output string has fixed width of 7 characters including null character at the end (string termination). The output string is right justified and the remaining positions on the left (if any) are filled with blanks.


Além de remover os espaços usando o Ltrim conforme já indicado, sugiro redefinir seu buffer de saída com o tamanho requerido pela IntStr.

Código: Selecionar todos
char txt[7];
Os homens mentiriam muito menos se as mulheres fizessem menos perguntas.
Avatar do usuário
barboza
Word
 
Mensagens: 948
Registrado em: 17 Out 2006 13:42
Localização: Longe de onde gostaria de estar


Voltar para PIC

Quem está online

Usuários navegando neste fórum: Nenhum usuário registrado e 1 visitante

x