View previous topic :: View next topic |
Author |
Message |
Gendrick
Joined: 11 Feb 2008 Posts: 8 Location: MATURIN, VENEZUELA
|
I need to know how put some chars in variables |
Posted: Mon Feb 11, 2008 2:00 pm |
|
|
I´m try to use this code
strcat(Dato, Entrada[3]); //la mes escribio con 3 y 4
strcat(Dato, Entrada[4]);
strcat(Dato, Entrada[2]);
But no work fine, can somebody help me, Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 11, 2008 2:32 pm |
|
|
You could use the strncat() function to append one character
to the 'Dato' string. Example:
The program below has the following output:
Code: |
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <string.h>
//======================================
void main()
{
char Dato[20] = {"ABC"};
char Entrada[10];
Entrada[0] = '0';
Entrada[1] = '1';
Entrada[2] = '2';
Entrada[3] = '3';
Entrada[4] = '4';
strncat(Dato, &Entrada[3], 1);
strncat(Dato, &Entrada[4], 1);
strncat(Dato, &Entrada[2], 1);
printf(Dato);
while(1);
} |
|
|
|
Gendrick
Joined: 11 Feb 2008 Posts: 8 Location: MATURIN, VENEZUELA
|
Thanks PCM |
Posted: Mon Feb 11, 2008 3:24 pm |
|
|
Thank PCM, there are one problem, i need that the variable are empty, no : char Dato[20]= {"ABC"};
When i use only : char Dato[20];
Appear two chart like this @@ and a face, can you tell me why ?.
Thanks again |
|
|
Gendrick
Joined: 11 Feb 2008 Posts: 8 Location: MATURIN, VENEZUELA
|
I realy need to get a string |
Posted: Mon Feb 11, 2008 3:34 pm |
|
|
I want to get a string that coming over the RS232 and then take each value, like 234.45, 543.75, ........ I need to take the 234.45 in one variable
Thanks |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 11, 2008 4:21 pm |
|
|
Use the get_float() function. It will receive a string and convert it to
a floating point value. Example:
Run the program below. Then type in a floating point number, such as
123.45 and then press the Enter key. The program will display the
number that it received. It will be stored in the 'value' variable.
Quote: | 123.45 value = 123.45
777.56 value = 777.56 |
Code: |
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <stdlib.h>
#include <input.c>
//======================================
void main()
{
float value;
while(1)
{
value = get_float();
printf(" value = %7.2f \n\r", value);
}
} |
|
|
|
Gendrick
Joined: 11 Feb 2008 Posts: 8 Location: MATURIN, VENEZUELA
|
|
Posted: Mon Feb 11, 2008 4:44 pm |
|
|
Thanks the problems is that the string is : 234.45, 8163.4, 957.342, 741.96, .........and i want to get every one, example K= 234.45 , M= 8163.4
x= 957.342 ...... Can you help me... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Feb 11, 2008 4:50 pm |
|
|
Where do the input strings come from ? Do they come from a GPS ? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Gendrick
Joined: 11 Feb 2008 Posts: 8 Location: MATURIN, VENEZUELA
|
Thanks |
Posted: Mon Feb 11, 2008 6:16 pm |
|
|
For your example I can take some part of the string, but i try to convert the string part to float with K = ATOF(Dato) but K is empty.....Thank for all |
|
|
|