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

Something about pointer in CCS C

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 19, 2009 2:40 pm     Reply with quote

To Kamputty:
Quote:

#include <stdio.h>

int main (int argc, char *argv[])
{
char comm[][50]={"How are you?","I am fine.","Thank you!","You are welcome!"};
char *p;
int x;

Your code doesn't compile in CCS (PCH vs. 4.099). Also, CCS doesn't
support argc or argv. You can't "return" from main(). There is no O/S
to return to.

-------------------------------------------------------
To cchappyboy:

Here is an example of how to get a pointer to individual elements
in a two dimensional text array. The program below has the
following output:
Quote:

Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Last Test: Wednesday


Code:

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

char weekday_names[7][10] =
{
{"Sunday"},
{"Monday"},
{"Tuesday"},
{"Wednesday"},
{"Thursday"},
{"Friday"},
{"Saturday"}
};   

void display_text(char *ptr)
{
printf("%s \r", ptr);
}


//======================================
void main ()
{
int8 i;
char *p;

// Pass a pointer to each array element.
// Display all of them.
for(i=0; i < 7; i++)
   {
    display_text(weekday_names[i]);
   }

// Get a pointer to one element in the array.
// Display it.
i = 3;
p = weekday_names[i];
printf("Last Test: %s", p);

while(1);
}

This was tested with PCH vs. 4.099.
cchappyboy



Joined: 03 Dec 2008
Posts: 45

View user's profile Send private message

PostPosted: Thu Nov 19, 2009 4:59 pm     Reply with quote

Thanks for you guys' help.
My ccs version is 4.066
This time I try this:
Code:

char comm[4][20]={"How are you?","I am fine.","Thank you!","You are welcome!"};

char *p;

p=comm[0];

printf("%s", p);

Pass the build procedure but it don't work.
But works at
Code:

printf("%s",comm[0]);

What is the problem? Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 19, 2009 5:49 pm     Reply with quote

Post your PIC. Always do this.
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