CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

I need to know how put some chars in variables

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Gendrick



Joined: 11 Feb 2008
Posts: 8
Location: MATURIN, VENEZUELA

View user's profile Send private message AIM Address Yahoo Messenger ICQ Number

I need to know how put some chars in variables
PostPosted: Mon Feb 11, 2008 2:00 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 11, 2008 2:32 pm     Reply with quote

You could use the strncat() function to append one character
to the 'Dato' string. Example:

The program below has the following output:
Quote:
ABC342

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

View user's profile Send private message AIM Address Yahoo Messenger ICQ Number

Thanks PCM
PostPosted: Mon Feb 11, 2008 3:24 pm     Reply with quote

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

View user's profile Send private message AIM Address Yahoo Messenger ICQ Number

I realy need to get a string
PostPosted: Mon Feb 11, 2008 3:34 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 11, 2008 4:21 pm     Reply with quote

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

View user's profile Send private message AIM Address Yahoo Messenger ICQ Number

PostPosted: Mon Feb 11, 2008 4:44 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Feb 11, 2008 4:50 pm     Reply with quote

Where do the input strings come from ? Do they come from a GPS ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 11, 2008 5:32 pm     Reply with quote

You answered yes in a PM, so you need find some sample code written
in CCS, that will parse a NMEA-0183 GPS stream.

Here is one:
http://www.readynote.com/gpscruise/gpscruiseCCSserLCD.zip
Look at the nema.c file.
Gendrick



Joined: 11 Feb 2008
Posts: 8
Location: MATURIN, VENEZUELA

View user's profile Send private message AIM Address Yahoo Messenger ICQ Number

Thanks
PostPosted: Mon Feb 11, 2008 6:16 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group