Jump to content

Using Environment Variables

- - - - -

  • Please log in to reply
5 replies to this topic

#1
AIGuy

AIGuy

    Learning Programmer

  • Members
  • PipPipPip
  • 64 posts
I usually stick to c# or java but i need something a little more low level so I'm trying c. I was wondering, how do you use environment variables like %windir%. I'm using tcc.

#2
brownhead

brownhead

    Programmer

  • Members
  • PipPipPipPip
  • 173 posts
See getenv - C++ Reference

#3
AIGuy

AIGuy

    Learning Programmer

  • Members
  • PipPipPip
  • 64 posts
this is the code
#include <c:\windows\tcc\include\stdio.h>

#include <c:\windows\tcc\include\stdlib.h>


void main()

{

   printf(getenv("CDir")+"\n");

}

and this is the output

test.c:6: can not use pointers here

any ideas?

#4
AIGuy

AIGuy

    Learning Programmer

  • Members
  • PipPipPip
  • 64 posts
oh, and CDir = "c:\windows\tcc"

#5
brownhead

brownhead

    Programmer

  • Members
  • PipPipPipPip
  • 173 posts
That is a strange error message, though probably not any stranger than one GCC would give you.

Anywho, you can't concatenate C strings by using the + operator. You need to use a special function. However, since your using printf you can simply say something like this.
printf("%s\n", getenv("CDir"));
Search cplusplus.com (don't be fooled by the name, it documents a lot of C functions as well since C is kind of a subset of C++) for printf to check out the full usage.

#6
AIGuy

AIGuy

    Learning Programmer

  • Members
  • PipPipPip
  • 64 posts
thanks.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users