Re: DOS program recording it's parameters and environment?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear Paul,

You are right, it works with Watcom C fine. And now I found in "Watcom C
Library Reference" manual paragraph:

environ
Prototype in <stdlib.h>.
This char ** __near data item is a pointer to an array of character
pointers to the environment strings.

which I not noticed before. Eeh, I still must learn to much!

Many thanks once again,
Franta

Paul Crawford napsal(a):
> Dear Frantisek,
>> compiler v1.9 (http://www.openwatcom.org/) for DOS. And there I knock
>> to problem - it seems as this compiler not support construction:
>>
>> int main(int argc, char *argv[], char *envp[])
> 
> I think this 3rd argument may be a MS-specific extension, as most C
> programs just have argc & argv in the call to main();
> 
> If you change to use the 'environ' variable, that should be pre-defined
> (probably in stdlib.h) and should do the same job. Attached is an
> example that seems to compile & work under C6 DOS compiler and with gcc
> on my Ubuntu 10.04 box.
> 
> Regards,
> Paul
> 
> 
> dosenv.c
> 
> 
> 
> 
> #include <stdio.h>
> #include <stdlib.h>
> 
> extern char **environ;
> 
> int main(int argc, char *argv[])
> {
> int ii;
> FILE *fp;
> char **envp = environ;
> 
> 
> 	fp=fopen("dosenv.txt", "wb");
> 	if(fp != NULL)
> 		{
> 		fprintf(fp, "argc = %d\n", argc);
> 
> 		for(ii=0; ii<argc; ii++)
> 			{
> 			fprintf(fp, "argv[%d] = %s\n", ii, argv[ii]);
> 			}
> 
> 		ii=0;
> 		while(envp != NULL && envp[ii] != NULL)
> 			{
> 			fprintf(fp, "envp[%d] = %s\n", ii, envp[ii]);
> 			ii++;
> 			}
> 
> 		fclose(fp);
> 		}
> 
> 
> return 0;
> }
--
To unsubscribe from this list: send the line "unsubscribe linux-msdos" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Console]     [Linux Audio]     [Linux for Hams]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite Camping]     [Yosemite Hiking]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Samba]     [Linux Media]     [Fedora Users]

  Powered by Linux