Setting global environment variables are OS specific, and are essentially managed by the OS itself. The OS is responsible for passing on the default environment values to new process spaces.

Therefore you will want to refer to your Operating system's requirements.

In Windows it is stored in the system registry. To access it from the command line you can use SETX or if you are including use the Windows API to access HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment or HKEY_CURRENT_USER\Environment.

In Linux it can be distribution specific, but at least in Ubuntu the environment is configured in the ~/.profile file.

Note that system() returns a program status code. It is good practice to use this value for error handling.

vibhu mishra commented: but i m still searching for the solution +0

I believe Labdabeta answered the first question well. As for your second question you can technically do this...

const *p = (const *)0x05;  // Constant pointer address
char *a = (char *)p;       // Assign this address to a character array
printf("%p", a);           // View the address of the character array

This will print out "0x5".

It is not advisable to work with pointers this way unless you are certain of the memory mapping. While programming in C you essentially give up control of the memory mapping and let C and the Operating System deal with that for you.

Of course if you are certain of the memory mapping (such as with embeded devices or OS programming) by all means create constants for these "POKE"-style addresses. This is usually done as a series of #define lines in headers.

Rahul47 commented: +1 for answering the second part. +4

These instructions assume you want to read it to memory and that the letters are being converted into numbers of equal size (1 byte):

  1. Open the file for reading
  2. Create a string array large enough to store the contents of the file.
  3. Iterate through each character of the file.
  4. Perform a translation using a switch before storing it into the array. Example:

    switch (inchar) {
        case 'A': memarray[i] = '1'; break;
        case 'B': memarray[i] = '2'; break;
        case 'V': memarray[i] = '3'; break;

At that point you can do whatever you want with the string array. If you intended to save it to a new file it would be more efficient to write it directly into the file instead of saving it to memory. If you need to do something more useful than write it to the screen you may consider in your translation stage to organize your data into indexed structures, but since you didn't specify how you wanted to use this data there's no way I could recommend what that structure would be.

symon_1 commented: I am not still getting it. I am sorry for asking you but can you write the code slightly so that i can have a better idea? +0

I just want to add that DaniWeb has an often neglected "search" feature which you might find handy. I did a search just now for your question and found literally over 1,900 results!

You should definately follow myk45's advice and learn the language grammar thouroughly before you embark on any programming project (Its not that hard.)

Once you are ready, you can take a look at this thread which explains a few techniques in detail: [URL=""][Thread] Need code to convert decimal to binary and binary to decimal.[/URL]

[QUOTE]I prefer to see people write inefficient code that is easy to read and understand rather than a clever, efficient algorithm that is inaccessible to the average coder[/QUOTE]

Comments are a requirement for any well written program -- complex code is valid as long as equal emphasis is given to its corresponding comments. For a very complex line of code, I like to write mini essays on the concept behind the algorithm in a comment block. I don't believe in "easy to read code" because code is not human in the first place. There is no excuse to write bad code, and there is no excuse to write bad comments.

I personally have a 60/40 ratio to all my unique code, where 60% is plain english and 40% is code. I don't care how redundant it is to write / increment the counter / as long as there is a consistent flow of explanation in the code. Additionally, my code in assembly language has about an 80/20 ratio of comments to code. Given all that effort, those who work with my code find it very easy to work with despite its highly optimized nature.

Now, this is my own opinion. Your statement is technically correct and is probably worth money.

This is a simple implementation of a switch-based scientific notation parser I came up with. I put lots of comments in there so you can build upon it and do more with it. I have tested it and it works fine with all your example inputs.

[CODE]double ScientificToDouble(char *in_String) {

// Loop Variables
int        Counter       = 0;
int        Length        = strlen(in_String) + 1;

// Flags and signs
int        NegativeFlag  = 0;
int        DecimalFlag   = 0;
int        ExponentSign  = 0;  // -1 = Negative, 0 = None, 1 = Positive

// Numerical Data
int        Exponent      = 0;
int        FinalDivision = 1;
long       Digits        = 0;

// Loop per each character. Ignore anything weird.
for (;Counter < Length; Counter++) {

    // Depending on the current character
    switch (in_String[Counter]) {

        // On any digit
        case '0': case '5':
        case '1': case '6':
        case '2': case '7':
        case '3': case '8':
        case '4': case '9':

            // If we haven't reached an exponent yet ("e")
            if (ExponentSign == 0) {

                // Adjust the final division if a decimal was encountered
                if (DecimalFlag) FinalDivision *= 10;

                // Add a digit to our main number
                Digits = (Digits * 10) + (in_String[Counter] - '0');

            // If we passed an "e" at some point
            } else {

                // Add a digit to our exponent
                Exponent = (Exponent * 10) + (in_String[Counter] - '0');

        // On a negative sign
        case '-':

            // If we passed an 'e'
            if (ExponentSign > 0)

                // The exponent sign will be ...

[QUOTE=amit_as;1696555]how to find the position of a particular character in a given string in c[/QUOTE]

Show an attempt at trying to do this yourself. It is more useful then just asking for the answer.

WaltP commented: that's what I said ;o) +17

[QUOTE]I think you completely missed my point. I threw it together to brain storm how I'm going to approach the logic of it. Instead of helping, you criticized my approach. All I asked was for help brain storming how I could approach this program. I don't care if C wasn't designed for mathematics, it was an assignment and I had to do it whether or not C was designed for mathematics. Neither of you bothered to post something similar, that could've helped. [/QUOTE]

All criticism is healthy criticism in my opinion. You are right about your post being a logic issue and not a programming issue -- this is exactly why I made a point to distinguish the two things. Your question implied that the programming language could do most of this logic on its own. The Trapezoidal formula you provided, in order to be compatible with C, must be broken down into more steps.

[QUOTE]Could've pointed me to some tutorials instead of being pricks about it.[/QUOTE]

I'm sorry you feel that way. The experts on this forum are generally better with C-specific questions than mathematical formulas. Had you provided the broken down logic, I would have been more than happy to help you turn that logic into C code complete with best practice tips.

C is not FORTRAN: It is not "made for mathematics". C is a system programming language, and as such, you must understand that it can't magically figure out what relationship your functions [B]f()[/B] are to each other by context. To make this work in C, as [B]WaltP[/B] explained, you must construct a series of steps that can be worked out by a human, then map that logic to a series of steps in the C language that emulates that procedure.

Also worth noting, your code produces no output and does no work because the functions that you wrote is never used by the [B]main[/B] function.

WaltP commented: You also can't make it work in ForTran as you are implying. forTran has the same limitations a C in this context. +17

The better question is: Can anyone HELP me with the logic to solve common emitter biasing of a BJT?

Logic is language independent. With that said, use this open source Java applet to help you with an accurate BJT simulation: [url][/url]

The source code is available on the site.

niyasc commented: Thanks brother. +1

[QUOTE=dellat;1647999]Has the following code any practical utility apart from showing the working of pointers?

Yes, that specific technique is highly employed in viruses for code injection.

if((strcmp( name, "positive" )) == 0); //note 6 parenthesis
if( strcmp( name, "positive" ) == 0); //note 4 parenthesis
Since [B]strcmp[/B] is not a macro, there is no compile difference between those two lines. Why do you add the extra parenthesis?

Here you go YAMNA MIDHAT! I hope you one day get a job at Microsoft.



int main(void) {
TextEdit TextEditor;
TextEditor.Default.Color = TD_BLACK;
while (Globals.Interface.ProcessMessages())
return 0;

What programming interest specifically do you have? Device drivers? Kernel/service modules? Single/Multi-threaded? Firmware? GUI? Gaming? Demo/Multimedia? Audio? Video? Software plugins?

How about project size? Project role? Project difficulty? Project depth and dimentions? How long do you want to spend on it? A role involving applying updates? Debuging? Testing?

Do you want money for it? Perhaps want to just practice your skills? You can jump into many open source C projects to add features or fix existing bugs.

Your question attracted my attention because, as Narue alluded to, its so tremendously unspecific that google would be your best starting point. Once you know what you think you want to do, type in a few keywords in google and you might find what you are looking for. Many current projects are still being made in C, but its usually found in low to medium level projects.

Personally, I use C mixed with a few high level languages in my projects. For instance, my designs are in XML and my database work is in SQL.

[B]> and neither am i running the app on a pc or mac[/B]

I love embedded programming! Its like crispy bacon in the morning for me. If you are running a unix/linux based OS, you could use system calls to embed the functionality of existing free or open source command line parameters. You can also pick any free open source decompressor and look at its publicly available source code.

If you are looking to embed functionality, zlib is a good one (i've used it), also look at this for RAR:


There are a ton of decompression code out there, just do some searches for "zip library" or "rar library" on google.

As for "which is best", it really depends on your application. If your program's objective is to [B]manage[/B] zip's and rar's, you don't need to worry much about how modern it is. You only need to worry about it if you are accepting random files provided by the user on a software intended to be used by the public. And in these cases, using libraries for [B]specific[/B] formats, such as zip or rar, would be better independent instead of "all in one".

Either way, there is a million of options for you. You are living in an era where these kinds of questions are nearly irrelevant. So have fun!

By the way, I find the arguments about "which is better, WinZIP and WinRAR?" kinda funny and totally out of place on this specific forum. Its like kids arguing ...

Someone told you that file operations are best for a multilingual dictionary application? Unless you phrased your question incorrectly, then you really should not listen to those people. It sounds to me like what you need is to learn about databases and how to work with them. In the year 2010, file operations should [B]only[/B] be used if databases can't do what you need it to do for your application. This is especially true for a program meant to [B][U]look up[/U][/B] words in [B][U]multiple languages[/U][/B]. Thats 100% database.

So look at any of these links for more information:





I agree with the reputation comment.

While I love a good challenge, especially in C, your presentation of it as a newcomer on this forum appears borderline spam. As a suggestion, don't start any paragraph in the English language with a sentence fragment such as "this is the output". The title of the thread is not the start of the message, its just a title.

Normally I would not be so critical about grammar, especially on a forum heavily involved with international students, but the lack of context in your post is self destructive, and my response is merely an attempt to correct said flaws in a constructive way.

Ancient Dragon commented: agree +34

Since I made this in a hurry, I programed it assuming I was going to use a format pointer, but I didn't need it. So your right, its useless.

As for the argv[x][y] thing, if your first parameter was "hex", then arv[0][1] would be 'e', the second letter of the first parameter. Therefore, its argv[param count][character]

By the way, I just caught a few errors with the code, specifically in the binary conversion sections. Simple mistakes. I will now repost the code with all the corrections including some additional comments to help you understand what I am actually doing. Thanks for your patience.

int num[2], // Where we will store both numbers
Result; // Where the result is stored
char Temp[256]; // Used in the binary conversions
int t, i; // Loop iterators

// Read and convert numbers.
// We are dealing with 2 parameters,
// so loop through them
for (t=0;t<2;t++)

// Grab the first letter of parameter 0,
// then parameter 3
switch (argv[t*3][0]) {

 // Convert Hex to Int
 case 'h': sscanf(argv[(t*3)+1], "%x", &num[t]); break;

 // Convert Octal to Int
 case 'o': sscanf(argv[(t*3)+1], "%o", &num[t]); break;

 // Read an Int
 case 'i': sscanf(argv[(t*3)+1], "%d", &num[t]); break;

 // Convert Binary to Int
 case 'b': {

     // Start the converted number at zero
     num[t] = 0;

     // Grab the binary string
     sscanf(argv[(t*3)+1], "%s", Temp); 

     // loop through the binary string in reverse order
     // since the least significant digit is on the
     // right side.
     for (i=strlen(Temp)-1;i>=0;i--) ...
mi.mac.rules commented: Thanks, you were a lot of help. +1

[B]> that is the same result if i change the void main into int main(void);[/B]

So not to let this point go unchecked, [B]void[/B] should never be used as the return of a C program's [B]main[/B] function. If you are learning C, and your intention is good programming techniques, don't use it. It may have the same results to you, but the question is more about code portability and good practice. The return value of a [B]void main[/B] is undefined [U][I]yet[/I][/U] the operating system requires some kind of return code, and you never want to have "undefined behaviour" in a program you write, it can lead to unexpected consequences, if not to you, to someone else in the future using your code.

[B]fscanf[/B] is a perfectly fine function to use for a configuration file with an absolute fixed format. I use it all the time. Wonderful function.

Here is an example which could be very relevant to you. This assumes linux. In windows, use the CR/LF combination.

This is the data structure.
typedef struct {
char IP[16];
int Port;
char FileName[255];
int Min, Max;
} DataStructure;
This is the code which performs the import. [B]fscanf[/B] used properly makes the import extremely painless.
DataStructure Data;
FILE *f = fopen("connect.conf","r");

if (fscanf(f, "%s\n%d\n%s\n%d\n%d", Data.IP, &Data.Port, Data.FileName, &Data.Max, &Data.Min)!=5) {
fprintf(stderr,"File not in correct format");
return -1;

[B]>> If the input file format is not fixed then this is a hard problem [/B]

Nothing is hard in C. If the file was not a fixed format, you just add a loop, int and switch.

[b]Person person = *p1;[/b]

This is copying the pointer address to the first 4 bytes of [b]firstName[/b] in the newly created instance of [b]Person[/b], and then completely undone by line 27:

[b]strcpy(person.firstName, "Modified1");[/b]

Which overwrites the 4 bytes written by the previous line of code with the given string constant.

If so, the compiler is ultimately treating line 26 as this:

[b]Person person;[/b]

So the pointer to [b]p1[/b] is not even involved here, which explains why it does not change the values pointed to by [b]p1[/b] as [b]jay1648[/b] explained.

Here is my explanation on the different ways to access a pointer:

void ModifyPerson(Person *p1)
// This technique, which you used in your code,
// is the pointer dereferencing method to access
// the contents of p1. Since the compiler knows
// p1 is a pointer, putting an asterisk in front
// of it tells the compiler that you want the
// value of the memory pointed to by the pointer.
// The parenthesis are a way to isolate the
// dereferenced pointer from the name of the
// element of that structure you want to access.
// The compiler knows the size and type of p1
// so it also knows what you are trying to say
// when you write "firstName" and "lastName"

strcpy((*p1).firstName, "Modified");
strcpy((*p1).lastName, "Modified"); 

    // This technique is accessing a pointer as 
    // an array. All variables in C are really 
    // instances of an array of one element. When 
    // you have any ...
jay1648 commented: Nice explanation ! +0


[b]This is 8bytes right? That's why I asked .. Now H takes 8 bytes.. [/b]

L"H" <-- This is 8 bytes because it is stores 2 characters. 2 x 4 = 8. It stores the letter H and \0, the null terminating character. In C, every string contains one extra letter which is added to the end by the compiler, and that's the null terminator which alerts many standard C library functions to know when the string actually ends, because without it the functions would not see the end of the string and keep on going, which is very bad.

So in linux, "H" is 2 bytes, "HI" is 3 bytes, L"H" is 8 bytes, L"HI" is 12 bytes.

I am not laughing, Vladimir Putin was trying not to laugh but he eventually didn't. Thing is, its not even cryptography. Its not even close. Its not even close to being close.

Say you chose a code that resolved to 1, very possible considering the result is casted to char, an 8 bit number, capable only to be 0 through 255. The final product will look nearly the same, and anyone can see that and say "oh, they just subtracted all the characters by 1". You would have to pick a code within a very small range to cause your encryption to hide the text, but one of the first things any hacker will do is check for patterns, and that range is itself a dead give-away. I just hope you don't ever use this method for something serious because it wouldn't work.

I am being critical about this because you asked for help making it better, but it can't be better, it has to be rewritten from scratch. This is not something to build upon like a template. Any good encryption is based on a good algorithm first, and coded second. What you are doing is coding first and trying to get a good algorithm second. It doesn't work that way.

sree_ec commented: well..well +1
Software guy commented: Yes I agree +3


[b]1. We are using L infront of format string to tell that It is expecting a wide character array Isnt it?[/b]

[b]"L"[/b] in front of a string tells the compiler to store the character array constant into a [b]wchar_t*[/b] array.

So "HELLO" written L"HELLO" gets stored like this in "H E L L O " with a final 4 byte null character. (In Windows its half that length)

[b]Why only 'A' is taken by %s?[/b]

Those spaces created by my example above are not spaces at all, they are null characters. That's because a [b]wchar_t*[/b] is describing an array whose element is each bigger than 8 bits, so in linux...

L"H" -> [0x48, 0x00, 0x00, 0x00] [0x00, 0x00, 0x00, 0x00]

The first set of 4 bytes represents an "H" in linux wide character format. The second 4 bytes is the terminating null character.

If you use a [b]wchar_t[/b] array in any place expecting a [b]char[/b], you will only get the first ASCII letter because the next immediate letter looks like a null terminating character. It doesn't know that its part of the first letter.

If you use any language other than English in your source code, or you want to give your program international support, always try to use [b]wchar_t[/b] or an [b]int[/b] array instead of the [b]char[/b] array. Not all functions support the wide character format, so in those cases you must use [b]char[/b], but whenever you can try to use the alternatives. It doesn't hurt anything.

[COLOR="Red"]@Ancient ...


printf() -- Prints formatted text to the screen.
sprintf() -- Prints formatted text to a string
swprintf() -- Prints formatted text to a wide character string.

Unlike printf() and sprintf(), swprintf() includes a "maxlen" to prevent buffer overflow.

So you use it any time you need to write formatted text to a wide character array.

In my application, I use it with __builtin_apply() and hack the argument list to modify the incoming parameters to auto convert some structures into compatible swprintf() elements.

You can't use the same name of the enum's within the same scope.

when you do this:
typedef enum A {
its about the same as doing this:
const int enum1 = 0;
const int enum2 = 1;
const int enum3 = 2;
So you can see that what your doing is redefining the same variable many times in the same scope.

Let me get this straight. So you want to prove to your peers that one technique is faster than the other, yet you are having trouble making the technique you are bragging about function correctly? Maybe its because the technique is flawed.

You see, multiplication in C using the multiplication operator '*' gets converted to something like this:

[b][COLOR="Red"]mov[/COLOR] bx, 10
[COLOR="Red"]mul[/COLOR] bx[/b]

Now the result of the multiplication by 10 is in bx. The clock cycles it takes to perform this is very little because the processor has logic gates executing a highly efficient [b]shift-add method[/b] at nearly the speed of light.

Now, you try [b]ANYTHING ELSE[/b] in C, and the compiler will absolutely add more lines of code to that. Like with that [b]NUM << MULT & NUM[/b], thats an initial [COLOR="Red"]MOV[/COLOR], an [COLOR="Red"]AND[/COLOR] with a [COLOR="Red"]SHL[/COLOR] and a final [COLOR="Red"]MOV[/COLOR]., more work than [COLOR="Red"]MOV[/COLOR] and [COLOR="Red"]MUL[/COLOR].

Even if you did this in assembly language it wouldn't be faster.

So I am frankly a little confused. Especially since [b]NUM << MULT & NUM[/b] is not the shift-add method. To shift-add, you need to have a loop and perform [COLOR="Red"]ADD[/COLOR] when the [COLOR="Red"]SHR[/COLOR] has a carry.. well there's more to it than that but, one single line of code won't really cut it.

Here is more information on the shift-add multiplication method.


Now don't get me wrong, the shift-add multiplication method is very fast, faster than conventional math you do on paper, but keep in mind almost every ...

I am interpreting your question in one of two ways:

(A) You are a genius, way beyond learning how to use existing database architecture. Still, given the C genius that you are, you need some advice on how to construct a database engine from scratch.

(B) You are a flat out beginner and don't know the first thing to databases but know enough to realize that you need to use one in C.

If (A), study this code:


Its open source and small enough for your genius mind to study in a few hours.

If (B), Do you know SQL language? Do you know how databases work?

If you need to know how databases work:


If you need to learn SQL, the language to work with databases:


If you need a free database IDE and interface to practice on:


Don't need practice? Just something simple to plug into C and store data with SQL language?


I hope this was helpful enough. Ambiguous questions lead to complex answers.

Adak commented: Outstanding post! +3

Here is the better explanation of your point Narue:

Read First: [url][/url]
Read Second: [url][/url]

So to clarify,
int *p = 0;
will compile to a "Null Pointer" (Not to be confused with the NULL macro), a special internal pointer guaranteed not to point to something meaningful, which may or may not be 0.

But to do this:
typedef struct { int *p; } P;

P *p = calloc(sizeof(P));

Probably won't accomplish the same thing because the compiler does not know (or need to know) the content of the structure in order to properly assign *P->p the "Null Pointer" appropriate for that pointer type.

So basically, the compiler keeps track of [b]((void )0)[/b], a value with a very special meaning to a C compiler (not to be confused by the macro NULL), and when it encounters it or an implied [b]((void)0)[/b] (as with [b]int *p=0;[/b]), the compiler will look at the type of pointer at its destination, in the case of my first example an int pointer, checks its own settings of ranges of valid pointer locations for that type, and assigns it an impossible pointer not in its tracked range, which may or may not be zero.

In other words, [b]((void *)0)[/b] (or pointer to zero) is tracked and converted in a sophisticated manner by the compiler to comply with the ANSI C requirement that the "Null pointer" be GUARANTEED to be unique for all pointers used in the application.

On a final note, the ...

Narue commented: Congratulations on learning something new. +23
nbaztec commented: :) +1