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

Using Array of string

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







Using Array of string
PostPosted: Mon Jan 07, 2008 4:08 pm     Reply with quote

Dear Users,
I need help about using array of String. (for PIC18F4550+CCS V4.057)
In my program, I initialize two arrays :
Code:

char LCDstring [10][10]={"OFF","ON","CH.","t=","Alm.","CODE","XXXX","Alarm1=","Alarm2=","mV"};
char LCDstring2 [3][20]={"Input-Output type ","Calculation type  ","Precision         "};

Then, I use this array in a fct to print on a LCD :
Code:

lcd(LCDstring2[0],1,0,_CURSEURDROIT);
lcd(echelle,1,20,_CURSEURDROIT);
lcd(LCDstring2[1],2,0,_CURSEURDROIT);
lcd(courbe,2,20,_CURSEURDROIT);

When I use the first array, it's working, but the second array, I don't have a good result ( on LCD, I see other variable)

Where is the problem ?
The solve my problem, I make this :
Code:

strcpy(strmenutemp,"Input-Output type ");lcd(strmenutemp,1,0,_CURSEURDROIT);
strcpy(strmenutemp,"Calculation type  ");lcd(strmenutemp,2,0,_CURSEURDROIT);
strcpy(strmenutemp,"Precision         ");lcd(strmenutemp,3,0,_CURSEURDROIT);

But, I prefer to understand my mistake.

More questions :
What is the difference between :
Code:

const char unites[] [*]={"ppb  ","ppm  ","mgr/l","ugr/l","%    "};
const char* pan_ids[] = {"aaaa", "bbbb", "cccc", "dddd", "eeee"};
char const *pan_ids[] = {"aaaa", "bbbb", "cccc", "dddd", "eeee"};
const char unitess[5][6]= { {"ppb  "},{"ppm  "},{"mgr/l"},{"ugr/l"},{"%    "}};


In this case, I need to use strcpy, to place this string in a array.
I try to use a pointer directly on this array ( with PIC18). IT,s working in a program test ( little code), But, when I use the same code in my big program, I have wrong result.

This is my code : (working in a program test, but not in my big program )
Code:

   compteurunit=0;
   *unite=unites[compteurunit];
   printf("\n\r unite=unites[compteurunit]           unité %s",unite);
   compteurunit++;
   *unite=unitess[compteurunit];
   printf("\n\r unite=unitess[compteurunit]          unité %s",unite);
   compteurunit++;
   strcpy(unite2,unites[compteurunit]);                                   
   printf("\n\rstrcpy(unite2,unites[compteurunit])   unité2 %s",unite2);
   compteurunit++;   
   strcpy(unite2,unitess[compteurunit]);
   printf("\n\rstrcpy(unite2,unitess[compteurunit])  unité2 %s",unite2);


Regards
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 07, 2008 4:39 pm     Reply with quote

The test program shown below can read the strings from the array.
It displays this output:
Quote:

Input-Output type
Calculation type
Precision

Code:
#include <18F4550.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

char const LCDstring2 [3][20]={"Input-Output type ","Calculation type  ","Precision         "};

//====================================
void main()
{
int8 i;
for(i = 0; i < 3; i++)
    puts(LCDstring2[i]);

while(1);
}
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Tue Jan 08, 2008 2:05 pm     Reply with quote

this might be useful:
http://www.ccsinfo.com/content.php?page=flexconst
http://www.ccsinfo.com/content.php?page=varconst
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