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

Passing array

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



Joined: 10 Oct 2012
Posts: 18

View user's profile Send private message

Passing array
PostPosted: Wed Oct 31, 2012 12:06 am     Reply with quote

I'm facing a spurious result while passing array to the functions.
For example, to compare two strings

Code:

char str1[6]="hello";
char str2[6]="hello";

if(strcmp(str1,str2)== 0)
  match found
else
  mismatch

If I use the above statement I'm not getting the correct output, however if I change the statement like this
Code:

if(strcmp(&str1[0],&str2[0]) == 0)
  match found
else
  mismatch

then I would able to get the correct answer. What will be the problem ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Oct 31, 2012 2:06 am     Reply with quote

Tell us the critical thing. _Compiler version_.
There was an oddity reported here a few weeks before with the handling of arrays and pointers on 4.134, and it could be this re-appearing in a different form...

Best Wishes
m_embedded



Joined: 10 Oct 2012
Posts: 18

View user's profile Send private message

PostPosted: Wed Oct 31, 2012 2:26 am     Reply with quote

Ttelmah wrote:
Tell us the critical thing. _Compiler version_.
There was an oddity reported here a few weeks before with the handling of arrays and pointers on 4.134, and it could be this re-appearing in a different form...

Best Wishes

my version is
ccs
IDE VERSION 4.127
PCB VERSION 4.127
PCM VERSION 4.127
PCH VERSION 4.129
PCD VERSION 4.127

and I'm using pic18f2620.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 01, 2012 12:42 am     Reply with quote

I tested the program shown below with vs. 4.127 and vs. 4.129 and it
works every time for me. It always shows match found. This was
tested in MPLAB simulator.
Quote:

match found

match found

match found

match found

match found


Code:

#include <18F2620.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#include <string.h>

char str1[6]="hello";
char str2[6]="hello";

//======================================
void main()
{

if(strcmp(str1,str2) == 0)
  printf("match found \r");
else
  printf("mismatch \r"); 

printf("\r"); 

while(1);
}
m_embedded



Joined: 10 Oct 2012
Posts: 18

View user's profile Send private message

PostPosted: Thu Nov 01, 2012 12:56 am     Reply with quote

PCM programmer wrote:
I tested the program shown below with vs. 4.127 and vs. 4.129 and it
works every time for me. It always shows match found. This was
tested in MPLAB simulator.
Quote:

match found

match found

match found

match found

match found


Code:

#include <18F2620.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#include <string.h>

char str1[6]="hello";
char str2[6]="hello";

//======================================
void main()
{

if(strcmp(str1,str2) == 0)
  printf("match found \r");
else
  printf("mismatch \r"); 

printf("\r"); 

while(1);
}


For me also its working with simulator, but when tested with the hardware I'm not getting the expected result. Thats why I have posted this question. What may be wrong in this case ?
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Thu Nov 01, 2012 1:56 am     Reply with quote

I took the time late last night to stick it into a 2620, and test it for real. Runs fine for me, compiled with 4.118, 4.127 and 4.134.
I'm wondering if there is a problem with your install. The file containing the chip details, is 'devices.dat', and this is version specific. I don't remember ever seeing a download that gives a different .pch version from the .pcm version, and since they share this file, wonder at seeing .pch at .129, with the other files all at .127.....

Best Wishes
m_embedded



Joined: 10 Oct 2012
Posts: 18

View user's profile Send private message

PostPosted: Thu Nov 01, 2012 5:30 am     Reply with quote

this thing is very strange , i have tried with different controller pic18f46k22 also , still the same problem exists , so i will uninstall every thing and install it again and going to try and see .. Thank you for your efforts ..
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