I have written the next simple program
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc<2) {
return 0;
}
else {
double x = atof(argv[1]);
printf ("%f\n", x);
return 0;
}
}
For example
./test 3.14
outputs
3.140000
Now I am trying to use this program with some other program, which gives outputs of the following form:
[3.14
Or just some other symbol in front of 3.14, but not a number. I want to use this output as input for the simple program I just showed, obviously I can't just pass this as an argument. My question is therefore how to accomplish this. I thought a lot about this problem, and tried to search the internet, but this is such a specific problem, I couldn't find answers. Thanks in advance.
./test $(./other_program | sed 's/[//').double x=atof(argv[1]+1);but then again you could circumvent the entire convert-to-double routine and justprintf("%s", argv[1]+1);