I want to see the result of a c programme (the value a of the "return a;" command of the "main" function). How can I do it in the terminal program of a Linux operating system.
1 2 3 4 5
int main(int argc,char *argv[])
{
int a=10;
return a;
}
If you want to automate it, just write a script of some sort:
Example called ShowReturn. You'd pass the program name into this script. It's written using the Korn shell, but can be easily adapted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/ksh
if [ $# -eq 1 ]
then
prog_name=$1
if [ -f ./$prog_name ]
then
$prog_name
print "$prog_name returned $?"else
print "File $prog_name doesn't exist"
exit
fi
else
print "Usage: ShowReturn <program_name>"
exit
fi
You'd run your program through it like so (let's assume your program is called a.out):ShowReturn a.out
Is there a way to get some other program's Return Value?
Like, I have a program that always returns 16, and a Launcher, how can I get the first program's Return Value from the Launcher?