#include <iostream>
using namespace std;
int main()
{
int name = 97;
cout << (char) name << "\n";
return 0;
}
Ok now thats correct and it works fine however I want to convert
6847 into it''s character equivalent. Now what is 6847 you ask? Well 6847 is supposedly my user id within the unix system, now computers don''t recognise characters and this is why the characters "pdstatha" (character equivalent of my user id) are stored as this number. So my question is how do I get it to convert from 6847 to pdstatha???
ASCII confusion
The following snippet of code takes the integer 97 and converts it to it''s character equivalent (which should be ''a'' ).
You might try looking at it from the other direction. Convert "pdstatha" into ascii and then try to figure out how 6847 came to be generated. Then reverse the process.
Hmph. There is no "character equivalent" to 6487.
Unix does *not* get it''s userid by translating your username into a number or anything like that. Typically you''ll find that root is uid 0, various daemon-users inhabit uid up to 499, and regular users are at 500 and up.
If you really want to start out with a userid and find the username of that user the best way is probably to grep the password-file.
-Neophyte
- Death awaits you all with nasty, big, pointy teeth. -
Unix does *not* get it''s userid by translating your username into a number or anything like that. Typically you''ll find that root is uid 0, various daemon-users inhabit uid up to 499, and regular users are at 500 and up.
If you really want to start out with a userid and find the username of that user the best way is probably to grep the password-file.
-Neophyte
- Death awaits you all with nasty, big, pointy teeth. -
Ok i think I'm starting to get somewhere, heres some more code
This gives the following output
112
100
115
116
97
116
104
97
[EDIT]
It doesn't??? Then why the hell did my tutor say that it did?
[/EDIT]
Edited by - pdstatha on February 18, 2002 9:25:13 AM
#include <iostream>using namespace std;int main(){ char name[8]; name[0] = 'p'; name[1] = 'd'; name[2] = 's'; name[3] = 't'; name[4] = 'a'; name[5] = 't'; name[6] = 'h'; name[7] = 'a'; for(int i=0; i<sizeof(name); i++) cout << (int) name[i] << "\n"; return 0;}
This gives the following output
112
100
115
116
97
116
104
97
[EDIT]
It doesn't??? Then why the hell did my tutor say that it did?
[/EDIT]
Edited by - pdstatha on February 18, 2002 9:25:13 AM
Those numbers don''t appear to add up to 6847 - maybe there''s some kind of formula used to derive 6847 Consider this 68 = D, 47 = /
After further studying, I discovered Neophyte was indeed correct, I have however found an alternate solution to grep. The following program will print out the username of a file owner.
Edited by - pdstatha on February 18, 2002 10:56:05 AM
#include <grp.h>#include <pwd.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <stdlib.h>void main(int argc, char **argv) { uid_t me1,me2; struct passwd *my_passwd; struct group *my_group; struct stat sbuf; me1 = sbuf.stuid; me2 = seteuid(me1); //this may need altering my_passwd = getwuid(me2); if(!my_passwd) { printf("Couldn't find out about user %d\n", (int) me2); exit(EXIT_FAILURE); } if(argv[1] != '\0') if(stat(argv[1],&sbuf) != -1) printf("file %s is owned by %s\n",argv[1], my_passwd->pw_name); else printf("Can't stat %s\n",argv[1]); else printf("Usage:%s file_name\n", argv[0]);}
Edited by - pdstatha on February 18, 2002 10:56:05 AM
Let me repeat myself a little more clearly:
On Un*ix systems there is absolutely *no* correlation between your username and your uid. None whatsoever. Period.
If your tutor said something that you interpreted that way there is a ~99.99% chance that you misunderstood what s/he said.
That said, there is an extremely slight theoretical possibility that your school/university/whatever has implemented some kind of hashing algorithm to give you your uid, but why anyone with a sane mind would want to do that is beyond me (it would be about as useful as hashing your birthdate to give you your usename (a lot less, actually, come to think of it)).
-Neophyte
- Death awaits you all with nasty, big, pointy teeth. -
On Un*ix systems there is absolutely *no* correlation between your username and your uid. None whatsoever. Period.
If your tutor said something that you interpreted that way there is a ~99.99% chance that you misunderstood what s/he said.
That said, there is an extremely slight theoretical possibility that your school/university/whatever has implemented some kind of hashing algorithm to give you your uid, but why anyone with a sane mind would want to do that is beyond me (it would be about as useful as hashing your birthdate to give you your usename (a lot less, actually, come to think of it)).
-Neophyte
- Death awaits you all with nasty, big, pointy teeth. -
quote:Original post by pdstatha
I rest my case
What case?
Ah, forget it.
I wanna work for Microsoft!
[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! ]
Thanks to Kylotan for the idea!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement