Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Problems with using string compare functions of string.h

Status
Not open for further replies.

sherazi

Banned
Full Member level 6
Joined
Feb 15, 2010
Messages
388
Helped
61
Reputation
126
Reaction score
61
Trophy points
1,318
Location
Muscat, Oman, Oman
Activity points
0
i am getting errors for using string compare functions of string.h
Code:
char m1[9]="00000000\0";
unsigned char numb[9]="00000000\0";
if (strncmp(m1,numb1,8)==0)

i get this error
Code:
Error	8	expected 'const char *' but argument is of type 'unsigned char *'
how can i solve this, I am using avrstudio5 and my target is Atmega644
 

Re: problems with stncmp

The compiler error indicates it expects a "const char *" and doesn't seem to like the "unsigned" type specifier.

Have you tried removing the type specifier "unsigned" :

original
Code:
unsigned char numb[9]="00000000\0";

rewritten
Code:
char numb[9]="00000000\0";

Also in the call to the strncmp(), you have:

Code:
if (strncmp(m1,numb1,8)==0)

shouldn't numb1 be numb

Code:
if (strncmp(m1,numb,8)==0)

The compiler didn't seem to complain about m1, so try removing the "unsigned"

And if all else fails, you can always cast

Code:
if (strncmp(m1,(const char *)numb,8)==0)

Try these suggestions and let me know the results.
 
Last edited:

Re: problems with stncmp

thanks .
replacing
Code:
unsigned char numb1[9]
with
Code:
char numb1[9]
solved the issue.

regarding numb and numb1 issue ,that was a typing error its numb1 everywhere
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top