My .c programme gives an object a ‘name’ when its created. I need to be able to excute different tasks depending on that name. I very new to this and have tried a couple of ways with no success. Here is what I had come up with..
if (name == "james"){
//Do a bunch of stuff
}
if (name == "tom"){
//Do a bunch of stuff
}
This was not successful. Is there a way so that if the ‘name’ is one thing it wont execute the others?
Thankyou so much for any help
In
C, a string is defined as a sequence of characters which are terminated with\0. A string constant is normally represented within `”, for example, char a[10] = “hello”.In order to compare two strings, you can use library functions like
strcmp()which is available instring.h. Doman strcmpto read more about this function.The strcmp could have been implemented in the following ways (array and pointer versions for your reference)