I am a C novice. I am trying to get the basename of a file(filename) without extension. The problem is much discussed in net, but due to my limited knowledge, I failed to make fruitful use of them, and thought I may use the unix command, as given.
char myCommand[512];
// char *basetmp=strrchr(filename,'/')+1;
sprintf(myCommand,"basename %s .bib",filename);
char *basefn=system((char *)myCommand);
variable filename is defined as char*.
This code is giving warnning:308:18: warning: initialization makes pointer from integer without a cast [enabled by default]
where line no 308 is "char *basefn=system((char *)myCommand);"
If anybody kindly show me where I am getting wrong, or better still, a better(and small) method to get the same function without unix command, it will be of huge help.
The C function system() does not return the "output" of the command it
executes. It returns an implementation-defined "status" which has
type int. (Most commands return 0 status to indicate success.)
In this case, the output from basename probably went directly to your
screen. One way for you to get the output, if your system supports
redirection (>>), would be to add " >> basename_output_file.txt" to
your sprintf format string and then open the file and read the output.
By the way, your cast in the call to system() serves no purpose.
myCommand is an array of char. In this context, the expression
myCommand is automatically converted to &myCommand[0] which already
has type char*.