View previous topic :: View next topic |
Author |
Message |
m_embedded
Joined: 10 Oct 2012 Posts: 18
|
Passing array |
Posted: Wed Oct 31, 2012 12:06 am |
|
|
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
|
|
Posted: Wed Oct 31, 2012 2:06 am |
|
|
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
|
|
Posted: Wed Oct 31, 2012 2:26 am |
|
|
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
|
|
Posted: Thu Nov 01, 2012 12:42 am |
|
|
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
|
|
Posted: Thu Nov 01, 2012 12:56 am |
|
|
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
|
|
Posted: Thu Nov 01, 2012 1:56 am |
|
|
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
|
|
Posted: Thu Nov 01, 2012 5:30 am |
|
|
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 .. |
|
|
|