LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-16-2008, 10:50 AM   #1
lrios
Member
 
Registered: Mar 2008
Location: Arg
Distribution: Cent0S
Posts: 48

Rep: Reputation: 15
Angry pass the variable contain


Hi all,
I try to pass the variable's contain for != functions.
I have an structure

Code:
struct struc_user {
	int *number_user;	
	char username[100];	
		
} users[MAX_USER];
with store the input of the users.
Like

Code:
printf("Which is your nick? \n");
gets(nick);
And my questions is how pass the variable contain, in my case char username, for != functions for example

Code:
room();
minus();
etc();
.
.
This structure will stored the input users.
 
Old 04-17-2008, 08:07 AM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,235

Rep: Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545
Irios, I suppose English is not your native language, but this is really difficult to understand.

I assume with 'contain' you mean 'contents'. The value of where the pointer point at.

But what is != function. Can you try to explain that with words and examples?

jlinkels
 
Old 04-17-2008, 04:06 PM   #3
lrios
Member
 
Registered: Mar 2008
Location: Arg
Distribution: Cent0S
Posts: 48

Original Poster
Rep: Reputation: 15
Well, when I write != i mean different(like c lol). In other words i want to pass value variable in differents functions. I write in my first thread some examples of pseudo-code.

I need help !
 
Old 04-17-2008, 05:28 PM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Do you want to pass the contents of, say, "username" for a particular user (i.e. element of your users array) to some function? You use the same array syntax as normal to access elements of the array and the . operator to access members of the structure. Here's an example:

Code:
  struct struct_user
  {
    int x;
  } users[10];

  users[0].x = 1;
  users[1].x = 2;
  printf("%d\n", users[0].x);
  printf("%d\n", users[1].x);
 
Old 04-17-2008, 07:58 PM   #5
lrios
Member
 
Registered: Mar 2008
Location: Arg
Distribution: Cent0S
Posts: 48

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Nylex View Post
Do you want to pass the contents of, say, "username" for a particular user (i.e. element of your users array) to some function? You use the same array syntax as normal to access elements of the array and the . operator to access members of the structure. Here's an example:

Code:
  struct struct_user
  {
    int x;
  } users[10];

  users[0].x = 1;
  users[1].x = 2;
  printf("%d\n", users[0].x);
  printf("%d\n", users[1].x);
Ok. this is true Nylex, but now my question is:

If I have this structure

Code:
int n_user;
struct struc_user {
	int *number_user;	
	char username[20];	
		
} users[100];
right, and I stored each username with

Code:
puts("Which is your username?");
fgets(users[n_user].username, sizeof(users[n_user].username), stdin);
-How can I identify which username is (logon) ?
username[1]="kevin"
username[2]="bob"
username[3]="mark"
.
.
-and how can i call each username in different functions, I mean:
room();
read_nick();
.
.
 
Old 04-17-2008, 08:14 PM   #6
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,235

Rep: Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545
Quote:
Originally Posted by lrios View Post
username[1]="kevin"
username[2]="bob"
username[3]="mark"
.
Not sure what you mean, but you access each username with:
Code:
users[n_user].username
and you can do a strcmp on each element to see if it matches. username[3] is really nothing, at most it is a record, but no string.

Quote:
Originally Posted by lrios View Post
Ok. this is true Nylex, but now my question is:
-and how can i call each username in different functions, I mean:
room();
read_nick();
You could pass a pointer to the function:
Code:
room (&users[1].username)
read_nick (&users[2].username)
jlinkels
 
Old 04-18-2008, 11:57 AM   #7
lrios
Member
 
Registered: Mar 2008
Location: Arg
Distribution: Cent0S
Posts: 48

Original Poster
Rep: Reputation: 15
users[n_user].username = "kevin"

users[n_user].username = "root"


Is ok this way ???
 
Old 04-18-2008, 05:56 PM   #8
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,235

Rep: Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545Reputation: 545
It looks good. n_user is an integer < 100 of course
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash how to pass value to variable in this function? babag Programming 10 04-03-2008 12:42 AM
Pass a variable as an agruement for cut chipmanchu Programming 1 05-25-2005 12:39 PM
How to pass env variable to KDE? koyi Linux - General 0 09-03-2003 04:29 AM
How do I pass a C variable to a Bash command ? Linh Programming 6 07-07-2003 04:12 PM
Pass text to variable Zed Linux - Software 6 05-12-2003 04:02 PM


All times are GMT -5. The time now is 06:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration