Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Passing External Enviroment Variable Problem

Status
Not open for further replies.

hednast

Newbie level 4
Newbie level 4
Joined
Aug 3, 2005
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,360
Hai....I am having problem in passing a value into an exe.

Eg:
c:\test.exe %computername%

the test.exe is a turbo c program.

I tried writing a small program that looks like below:


main(char *val)
{
printf("Value is %c ",val);
}


But I cannot get the value as I want. Please help.....
 

Try this:
Code:
void main(int argc, char* argv[])
{
    int count;

    for(count=1; count <= argc; count++)
        printf("Value is %c \n",argv[count]);
}

hope this helps and best regards
 

Hai C-Man,

Thanks 4 ur help. I tried compiling it and running it but it does not seem to work. I get values like shown below. Paratest is my exe where I paste the code sample u posted in reply.

**********************************************
D:\TCPP\BIN>paratest 2 ha
Value is ≈
Value is ∙
Value is

D:\TCPP\BIN>paratest hai
Value is ∙
Value is
**********************************************

Please asists. Thank you.

Regards,
Hednast
 

Hey C-Man, you must be half-asleep!

void main() is an error.
%c is an error.
count <= argc is an error.
missing stdio include.

Try this:
Code:
#include <stdio.h>

int main(int argc, char *argv[])
{
  int count;

  for (count=1; count < argc; count++)
    printf("Value is %s\n", argv[count]);
  return 0;
}
Or the compact version:
Code:
#include <stdio.h>

int main(int argc, char* argv[])
{
  while (*++argv)
    printf("Value is %s\n", *argv);
  return 0;
}
 

    hednast

    Points: 2
    Helpful Answer Positive Rating
Sorry posted just a code fragment with the idea to leave a little work to the original poster :D

best regards
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top