Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

re compiler fails

Status
Not open for further replies.

uadmin

Technical User
Jun 13, 2001
122
GB
Hi
I have tried to compile the code below with the following command on hpux - cc -Aa -o ouput.exe myproc.c

code :

#include <stdlib.h>
envvar=getenv(&quot;TERM&quot;);
printf(&quot;The value for the environment variable TERM is &quot;);
if(envvar)
{ printf(&quot;%s\n&quot;,envvar); }
else { printf(&quot;not set.\n&quot;); }
}
After i try to compile i get the following message :
# cc -Aa -o ouput.exe myproc.c
cc: &quot;myproc.c&quot;, line 2: warning 557: Missing declaration specifiers, &quot;int&quot; assumed.
cc: &quot;myproc.c&quot;, line 2: error 1521: Incorrect initialization.
cc: &quot;myproc.c&quot;, line 3: error 1000: Unexpected symbol: &quot;The value for the environment variable TERM is &quot;.
cc: &quot;myproc.c&quot;, line 4: error 1000: Unexpected symbol: &quot;if&quot;.
cc: &quot;myproc.c&quot;, line 3: warning 557: Missing declaration specifiers, &quot;int&quot; assumed.
cc: &quot;myproc.c&quot;, line 3: error 1506: Parameters allowed in function definition only.
cc: &quot;myproc.c&quot;, line 6: error 1000: Unexpected symbol: &quot;else&quot;.
cc: &quot;myproc.c&quot;, line 6: error 1000: Unexpected symbol: &quot;;&quot;.

Could anyone please advise me where i am going wrong.

Regards
Simon
Simon Peter Wickham
Email: s.wickham@zoom.co.uk
 
Hi

Maybe i need to break it down a bit...
First i have the above code which when i try to compile reports errors.So what i would like to know is there a problem with the code or is it the way i am trying to compile it.

Thanks
Simon Simon Peter Wickham
Email: s.wickham@zoom.co.uk
 
You need to have a main function. Your code needs to be inside the a function (in this case main) for it to execute. getenv() returns a char *, and your envvar is defaulting to an int, so you can't assign it.

#include <stdlib.h>
char *envvar=getenv(&quot;TERM&quot;);
^^^^^^
int main() {
^^^^^^^^^^^^
printf(&quot;The value for the environment variable TERM is &quot;);
if(envvar)
{ printf(&quot;%s\n&quot;,envvar); }
else { printf(&quot;not set.\n&quot;); }
}

I added two things to your code (you already had the closing brace for the main function). That should compile, but in your if test, I believe you want it to check whether envvar == &quot;&quot;.

Hope that helps.
 
Thanks for the help.
Simon Simon Peter Wickham
Email: s.wickham@zoom.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top