Home

Forums

Web development

 

 

 

 
     
 
dna88 Web development and Technology Forum
 
Profile   Register   Memberlist   Usergroups   FAQ   Search  Log in
prinf pointer from within a struct

 
Post new topic   Reply to topic    dna88 Forum Index -> Programming in Java, C, C#, VB, .NET Discussion Forum
Author Message
rod
Just In
Just In


Joined: 02 Aug 2004
Posts: 1

Post Post subject: prinf pointer from within a struct Reply with quote

I am trying to write a password program on a unix machine. the problem I have, is a simple one, I get seg faults when I try to printf the pointer within the struct, "mypasswrd". I have looked everywhere to see how to do this but it doesnt seem to be possible to dereference the pointer in the printf statement.
I have included the .h file here.
the .c file is my test prog, all the linking is done and the libs are no problem I am just stuck on this aparently simple problem

#include <sys/types.h>
struct mypasswd {
char *pw_name;// user name
char *pw_passwd;//user password
uid_t pw_uid; // user id
gid_t pw_gid; // group id
char *pw_gecos;// real name
char *pw_dir; // home directory
char *pw_time;//time last modified
};
struct mypasswd* mygetpwnam(const char* name, const char* filename);

struct mypasswd* mygetpwuid(uid_t uid, const char* filename);

int mygetpw(uid_t uid, char** buf, const char* filename);



#include <stdio.h>
#include "mypassword.h"
#include <string.h>

int main()
{
FILE *fptr;
struct mypasswd TempPw;
int uid, gid;
char name[30],passwd[20],gecos[20],dir[25],login[20];

if( (fptr = fopen("mypassword.txt","r")) == NULL)
{
printf("failed to open");
}
while( (fscanf(fptr,"%[^:]:%[^:]:%d:%d:%[^:]:%[^:]:%s\n",name,passwd,&uid,&gid,
gecos,dir,login)) != EOF)
if(uid == 114773)
{
printf("%s:%s:%d:%d:
%s:%s:%s\n",name,
passwd,
uid,
gid,
gecos,
dir,
login);

TempPw.pw_uid = uid;
TempPw.pw_gid = gid;
TempPw.pw_name = name;
/* printf("%s:%d:%d\n",
*TempPw.pw_name,
TempPw.pw_uid,
TempPw.pw_gid);*/
}
fclose(fptr);
// return TempPw;
//printf("record not found");
//fclose(fptr);
return 0;
}
_________________
Rod Bone
Sydney
Australia
Mon Aug 02, 04 6:51 pm
Back to top
rod View user's profile Send private message MSN Messenger
Belal
User
User


Joined: 08 Mar 2004
Posts: 84
Location: Dhaka, Bangladesh

Post Post subject: Reply with quote

hi rod, could you please make the following section more clear? What do you realy want to get from your program? if i be more clear, hope i can help you.

Quote:
I get seg faults when I try to printf the pointer within the struct, "mypasswrd". I have looked everywhere to see how to do this but it doesnt seem to be possible to dereference the pointer in the printf statement.


......
belal
_________________
we've lot of things to think abt curr probs
so, i don't have time to think abt religion or wonder of sceice .......... how ppl can waste their time like this?
Sat Aug 07, 04 3:50 am
Back to top
Belal View user's profile Send private message Yahoo Messenger MSN Messenger
Belal
User
User


Joined: 08 Mar 2004
Posts: 84
Location: Dhaka, Bangladesh

Post Post subject: Reply with quote

hi rod, could you please make the following section more clear? What do you realy want to get from your program? if i be more clear, hope i can help you.

Quote:
I get seg faults when I try to printf the pointer within the struct, "mypasswrd". I have looked everywhere to see how to do this but it doesnt seem to be possible to dereference the pointer in the printf statement.


......
belal
_________________
we've lot of things to think abt curr probs
so, i don't have time to think abt religion or wonder of sceice .......... how ppl can waste their time like this?
Sat Aug 07, 04 3:50 am
Back to top
Belal View user's profile Send private message Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    dna88 Forum Index -> Programming in Java, C, C#, VB, .NET Discussion Forum All times are GMT - 7 Hours
Page 1 of 1

 

Partners and Resources

Bangladesh hosting company

Bangladesh web design

Driven by phpBB © phpBB Group