
Originally Posted by
LaRoza
No simple way.
Do you have to use bash?
Well, I suppose the answer is now yes. As I can't find a way to convert an input argument to its ascii number in C. (ie: a into 97)
Because argv[1] is treated as a string, not a character.
So printf ("%s", argv[1]); is the only way to properly print the input argument. (%c will print some random gibberish).
but I can extract a number from an input argument.
ch = (int)strtol ( argv[1], NULL, 10 );
So I figured that it may be easier to use a language that treats it's input arguments as characters...
Hence why I ask if BASH can do this. So I can execute the C program with the number argument of the char I want.
Hope this makes sense.
Regards
Iain
[EDIT]
Here's a brief example of what I was trying to (and have now) acheive.
Code:
___________________________________
#!/bin/bash
ch=$(printf '%d' "'$1")
./cprog $ch
___________________________________
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int ch = (int)strtol (argv[1], NULL, 10);
/*
switch to react to the inputted argument
*/
return 0;
}
___________________________________
Bookmarks