Compare char array [closed] - c++

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Hi I'm doing an assignment and in this part of it I need to check if a word I have entered into a char array is equal to a word stored in a structure array. This is what I have but it doesn't work:
if (CDdata[i].artist == search)
Can someone please help me compare the item in the structure array to the char array?
Thanks.

Assuming that CDdata[i].artist and search are char* or const char*, all you're currently doing is comparing the pointers not the values.
You need to use something like if (strcmp(CDdata[i].artist, search)) which will return 0 for equality.
strcmp is a standard function in the C standard library.

You can use the strcmp function in the c standard library.
if (strcmp(CDdata[i].artist, search) == 0)

Related

what is the best data structure in this case? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
what is the best data structure in this case? I am using c++. yes I am a newbie.
Function getValues
Inputs:
ID // string
StatType // enum
Output:
value // double
There is a bunch of data which can be organized as a two dimensional array. The function should check the ID and the stat Type and return the appropriate value.
This appears to be a specification for a function, not a data structure. The function declaration would look something like this:
enum enumtype { ... };
double getValues(std::string ID, enumtype StatType);

How to print a character code from char*? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm getting a character from a user input using getchar(), but instead of using cout to print the character I want to print the character code, like the one for Return, ESC, etc, so I can use in my code later to check using a if.
To do this you can cast the char to an int,
int charval = (int) mychar;
printf("%d\n", c); will show you the character code.
so I can use in my code later to check using a if.
You don't need to expicitly convert it to an int for that.
if(getchar() == char_code)
doSomething();
Cast the char as an int and print the int value.

How to manipulate CString's content [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
guys, I have a problem, please help me!
I have a CString variable which will receieve from Database,and the data may like this:(8)(9)(10)(11) or more.
Now I want to change every number in CString,for example, add 1,the outcome should like this:
CString Data; the contest of CString data variable should be changed.
Before: (8)(9)(10)(11)
After: (9)(10)(11)(12)
I've tried Data.GetAt(i),but it returns a const pointer and I can't change it.
I konw maybe Data.GetBuffer() can get a pointer to manipulate CString,but I don't know how to do it.
So please help me ! Thanks a lot!
Don't change in-place. Specifically in your example, when you change (9) to (10) it needs 1 extra character of buffer space. Extract all the values somehow (a std::list of int perhaps), add whatever numbers you need, and then re-assemble into a string, and write it back all at once.

c++ conversion const member [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a member L that is a list of pairs of ints which I would like to use in a const function. I'm hence not supposed to modify L, but I don't know how I can iterate through L, to read its contents (as opposed to modifying them).
The compiler keeps saying there is a conversion issue.
Assuming you are using std::list<std::pair<int,int>> you need to use std::list<std::pair<int,int>>::const_iterator as the type for your iterator.

validating the value in a integer...? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
how do v find a value in an integer is garbage or not???
Initialize it at point of declaration, and it can never be garbage.
Pass it to strfry and compare the returned value with the original.
I guess that you mean if a string contains a valid integer. Check out scanf or the stream equivalent of c++, or Boost lexical cast