System calls in c
Hi Everyone. I'm having problems with system calls, basically the commands that i can put into my terminal are fine but don't work as system calls from c.
I'm using tcsh.
In other words:
and in C:
(23) dino-shill:>setenv W_DIR widthdirectory
(24) dino-shill:>echo $W_DIR
if(width < 20)
system("setenv W_DIR 2amp/eps/10mto20m");
Is it because the c program is using sh while i am using tcsh?
sh: setenv: command not found
How do i tell the program to use tcsh?
Try using the setenv() and getenv() functions for environment variables.
You seem confused about what system() does. It invokes a shell, runs the command, then returns. That means that anything you do in that system() call will not "stick." You can't change directories, and you certainly can't set environment variables.
Like Todd Burch said, you have to call setenv() and getenv() directly.