Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple character string problem 1

Status
Not open for further replies.

robinsql

Programmer
Aug 2, 2002
236
IE
Hi,
I'm passing in a charcater array inCurrency and am wondering how I see if this is equal to a certain value such as pound. I have entered in pound earlier in the program into the array but I suppose it has other characters after the first five letters. Do I need to trim the array or something? Any help gratefully received.
void calculate_data(int amount, char inCurrency[9], char outCurrency[9])
{
if(inCurrency == "pound" )
{
printf("%d, %s, %s", amount, inCurrency, outCurrency);
}
}
 
Use strncmp :
if (strncmp(inCurrency, "POUND", 5) == 0)

HTH Dickie Bird (:)-)))
 
you want to use strcmp and if it returns zero they are equal.

if(strcmp(inCurrency,"pound") == 0)

Just a reminder... this is case sensitive

Matt
 
Thanks to both of you. That works fine.
Robin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top