View previous topic :: View next topic |
Author |
Message |
Johann17943
Joined: 11 Dec 2010 Posts: 11 Location: Germany
|
string operation |
Posted: Thu Nov 22, 2012 11:16 am |
|
|
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
|
|
Posted: Thu Nov 22, 2012 12:29 pm |
|
|
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
|
|
Posted: Thu Nov 22, 2012 1:57 pm |
|
|
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
|
|
|
Johann17943
Joined: 11 Dec 2010 Posts: 11 Location: Germany
|
|
Posted: Sat Nov 24, 2012 8:26 am |
|
|
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
|
Error during compilation |
Posted: Sun Dec 02, 2012 2:16 pm |
|
|
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: 19539
|
|
Posted: Sun Dec 02, 2012 3:15 pm |
|
|
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
|
|
Posted: Sun Dec 02, 2012 3:15 pm |
|
|
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
|
|
Posted: Mon Dec 03, 2012 2:14 am |
|
|
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. |
|
|
|