ASCII confusion

Started by
12 comments, last by pdstatha 22 years, 2 months ago
I know how to turn strings into numbers:
  unsigned long n = ''a'' << 24 | ''s'' << 16 | ''d'' << 8 | ''f'';  

It only works for strings with 4 or less characters, though.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Advertisement
LOL
This is like "Who''s on first?"
There is no correlation between the UID and the username. The snippet of code that you say proves otherwise does not. What that code does is query the system database; that's it. Each UID is associated with each username by the system, but the UIDs are not generated from the usernames; there is no mathematical correlation.

To understand the idea, look at this code. Then try to write a second program to associate an arbitrary name with a uid. You won't be able to. The reason this program can do the association is that it has access to several arrays, which are analagous to the system database previously mentioned.
      #include <stdlib.h>#include <string.h>#include <iostream>using namespace std;int main(){   char name[10][128];   unsigned long uid[10];   char getname[128];   int i;   for(i = 0; i < 10; i++)   {         cout << "Input username:\t";         cin << name[i];         uid[i] = rand();   }   cout << "Done generating UIDs for 10 names.\n";   cout << "Input a name to retrieve a UID: ";   cin >> getname;   for(i = 0; i < 10; i++)   {        if(strcmp(getname, name[i]) == 0)        {              cout << "UID:\t" << uid[i];              break;        }   }   return 0;}      




Edited by - TerranFury on February 18, 2002 11:56:11 AM
Yeah sorry getting my terms mixed up, I didn't mean that you could directly derive username from uid. I meant given the uid you can get the username.

[edit]
Updated code that works

  if(argv[1] !='\0'){   if(stat(argv[1],&sbuf) != -1){      me1 = sbuf.st_uid;      me2 = me1;      my_passwd = getpwuid(me2);      if(!my_passwd){         printf("Couldn't find out about user %d\n", (int)me2);      }      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 3:46:05 PM

This topic is closed to new replies.

Advertisement