Operating System - HP-UX
1820882 Members
3358 Online
109628 Solutions
New Discussion юеВ

Re: getuid() and C Program

 
SOLVED
Go to solution
Ian Dennison_1
Honored Contributor

getuid() and C Program

I am having great difficulty in writing the following C program,..

main()
{
int curruid;
char commandline[1024];

curruid=getuid();
strcat(commandline, "/usr/local/bin/script1.sh ");
strcat(commandline, curruid);

system(commandline);
}

This program is designed to get the current uid of the person running the program and pass it to the Shell script for validation. However, C will not permit me to convert the integer value of getuid() to a string to concatenate to the command line. I have tried various combinations and all end up using the number passed as an ASCII value rather than its actual value.

Anyone know of any methods of converting this?

Thanks, Ian Dennison
Building a dumber user
2 REPLIES 2
RikTytgat
Honored Contributor
Solution

Re: getuid() and C Program

Hi,

use:
sprintf(string, "%i", curruid);

The string 'string' will contain the current uid.

Bye,
Rik
Ian Dennison_1
Honored Contributor

Re: getuid() and C Program

Thanks Rik, magical answer!
Building a dumber user