This is how I would write your block o' code:
#include<cstring>
for (int j=0;j<size;j++)
{
if(strcmp(a[j].n, name)
{
strcpy(a[j].n, name);
break;
}
}
The code I provided you is untested. Please let me know where any additional errors are with line number.
Some rules to remember:
you can use all boolean logic when at the 'char' level (comparing 'chars' to 'chars') you can also assign chars to other chars.
You cannot directly use boolean logic to directly compare c-strings to other c-strings (arrays to arrays)
You can assign an array pointer to an array pointer of the appropriate type (assign an array to an array pointer) if the appropriate amount of memory has been allocated.
Only if you are using <string> class objects can you compare to 'string' type variables using == equality test, or assign one string to another using the = assignment operator, or 'concantinate' (add to) an existing string using the += 'accumulation' operator.
Last edited by Clinton Portis; Nov 7th, 2009 at 2:10 pm.
Reputation Points: 237
Solved Threads: 117
Practically a Posting Shark
Offline 822 posts
since Oct 2005