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 CCS Technical Support

string operation

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



Joined: 11 Dec 2010
Posts: 11
Location: Germany

View user's profile Send private message

string operation
PostPosted: Thu Nov 22, 2012 11:16 am     Reply with quote

Hi there!
I want to use a string array to use different language for printf(printlcd..)-function. My idea is to put all strings that I use in a 2-dimensional array, where the first is the English string and second the other language.
I could use the following code, but it seems to be not a very nice programming
Code:
if (i==0) printf(printlcd,"german");
else printf(printlcd,"deutsch");

I would like something like
Code:
printf(printlcd,text[i,7]);
this should show the according string while i=0 for english and i=1 for other language.
One string is maximum 16 characters long (according to one display line).
Could anybody help me? I'm working with PCWH 4.138 on PIC18F4550 (8% RAM used until now).
Thanks.
Johann
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu Nov 22, 2012 12:29 pm     Reply with quote

Declare a variable 'language'.

Use arrays as you suggest.

When language == 0, prints in english.
When language == 1, prints in other.

Mike
Johann17943



Joined: 11 Dec 2010
Posts: 11
Location: Germany

View user's profile Send private message

PostPosted: Thu Nov 22, 2012 1:57 pm     Reply with quote

Hi Mike,

thanks, but how to declare the arrays (strings)? And where to store them (RAM, EEPROM, Program Memory? The strings should not have all the same length (min. 3 characters, max. 16). Is that possible? Anyway I will try to use for the two languages the same length.
Could you give me an example? What header files do I have to include?

Thanks.
Johann
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 22, 2012 7:18 pm     Reply with quote

There are many threads on this topic. There are many complex variations
of how to store strings and how to pass a pointer to them:
http://www.ccsinfo.com/forum/viewtopic.php?t=48456
http://www.ccsinfo.com/forum/viewtopic.php?t=30610&start=1
http://www.ccsinfo.com/forum/viewtopic.php?t=41353

If you're a newbie, I suggest that you just put the string in a printf
statement:
Code:

#include <16F877.H>
#fuses HS, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//====================================
void main()
{
printf("Hello World\n\r");

while(1);
}
Johann17943



Joined: 11 Dec 2010
Posts: 11
Location: Germany

View user's profile Send private message

PostPosted: Sat Nov 24, 2012 8:26 am     Reply with quote

Thanks!
I was searching but, as you say, there are many threads. This helped me to save a lot of time.
Regards,
Johann
catacomsa



Joined: 29 Oct 2009
Posts: 3

View user's profile Send private message

Error during compilation
PostPosted: Sun Dec 02, 2012 2:16 pm     Reply with quote

Hello All,

I'm a beginner in micro controllers
I create a short code, the idea is to pass a string to a function, but with no success...

Code:
#include "18F4550.h"
#DEVICE ICD=TRUE
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN,MCLR,DEBUG
#use delay(clock=48000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)


void prints(char *s)
{
printf("%s",*s);
}
void main (void)
{
prints("test");
}


The error:

    *** Error 90 "main.c" Line 17(14,15): Attempt to create a pointer to a constant
    1 Errors, 0 Warnings.


Seems that the function can not handle a string
why this error? what is wrong?

PS: Sorry for my English
Ttelmah



Joined: 11 Mar 2010
Posts: 19481

View user's profile Send private message

PostPosted: Sun Dec 02, 2012 3:15 pm     Reply with quote

How about searching the forum?. This has been covered in thousands of threads...

Code:

char str[]="test";

prints(str);


Key is that "test" is a _constant_ string, not a RAM string.

Best Wishes
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sun Dec 02, 2012 3:15 pm     Reply with quote

Your code is neither complete nor compilable, so we can't test it!

Mike

No PIC type, compiler version etc.
Read the CCS forum guidelines.
catacomsa



Joined: 29 Oct 2009
Posts: 3

View user's profile Send private message

PostPosted: Mon Dec 03, 2012 2:14 am     Reply with quote

Hello,

@ Ttelmah
Thanks for hint, I'll try in this afternoon.
I have to dig a bit more to understand all details.

@Mike Walne
I use the following setup:
- PIC 18F4550 , 20MHz quartz, serial communication with PC
- CCS V4.114 (I used MPLAB as IDE)

Sorry for inconvenience by posting on this thread.
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