Search code examples
cdosc89turbo-c

Is there any way to accept all the parameters as a single string?


For example,

Input:

echo( hello world

Program:

#include<stdio.h>

int main(int n,char** args){
// Replace all the '\0' with ' '
system(args[1]);
return printf("\n");
}

Output:

hello world

Now I need hello world in a pointer.

I know that **char doesn't work the way I want it to..

But is there any efficient way out, instead of calculating the length of each argument, malloc-ing those many bytes and then concatenating it to the allocated memory?

Some access specifier for char** maybe?

I am trying to add echo( a command to DOSBox, so basically echo params and then print a newline. That's it.

Also, is there any way to exclude to recognize an exe without any spaces or is it console specific?


Solution

  • To echo an empty line, in Windows cmd, the best method is echo(, but also common are echo/, echo. and some more variations.

    The (best for cmd) echo( doesn't work in DOS (results in a bad command or filename error), but echo/ works fine even in DOS.