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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"scanfed" char* to struct?

Status
Not open for further replies.

hightimePT

IS-IT--Management
Jun 27, 2010
2
PT
Hi.
I'm coding a user/pass autentication system, and I got a struct user with all the data needed by the system about users.

void create_user(char* username, char* password, char* nc, time_t dr){



struct user username;




username.username = username;

....

I'm getting a type error:

error: incompatible types when assigning to type ‘char *’ from type ‘struct user’


How can i name each user struct from a char*??


thanks for help in ad vance.
 
In the modern C both usernames: parameter username and local struct variable username have the same (block) scope. So it's an incorrect name redifinition case.

As far as I know in old C an username from the parameter list was hidden by inner struct declaration so you are trying to assign struct username (not parameter char* username) to the username member. Of course, it's impossible.

Moral: stop playing with namesakes...
 
I understand the error.
so how can I identify different user structs? any ideia??
 
Seems to me the best way is to pass a pointer to the structure where any part of it can be accessed. Unless you are in "most obfuscate C" competition, I would call it something clear and simple. You know you are creating a user, so call it (the structure) "usr", since it isn't a username. Also from a parser point of view, I don't know if it's got enough information to properly associate what you want, since most are multiple pass parsers. It also helps to show more code. Like, is username defined as an array of char or a pointer to char, in which case where is it going. Also a type error usually indicates a mis-match between what's on the left to what's on the right, so I would suspect a mis coded source, irrelevant to your inclination of obfuscation.

Still think the simple approach is pass a pointer to the structure and that makes it clear what's going on.

I believe you could contextually get away with what you are doing, but unless you are the only one to maintain it, even you will forget what you did. Use the KISS (Keep It Simple Stupid) principle, you'll be glad you did.

Just something too keep in mind.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top