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 <windows.h> 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.

I didn't make any assumptions. I was always avoiding using flags in the way I described but decided today to ask what you guys thought about it purely out of curiousity.

In my applications I tend to use mutex locking as a multi-threaded resource protection mechanism.

Thats what I thought too which is why I've been naturally avoiding using them in that way, but it would have been so convinient and elegant if it did. Thus is life in the world of the compiled.

You may be suprised how heavily used console interfaces are used in these modern times. I work with them and build them on a near daily basis in Linux for high end modern enterprise software.

As much as I love building things from scratch, I also consider the value of using a robust and community tested system like ncurses, cdk, and dialog which lets you get straight to the menu building. But then again you'd miss out on some really great coding practice.

Say I have code like this...

typedef struct {
    unsigned A:1;
    unsigned B:1;
} FlagStruct;
extern FlagStruct *Flags;

Imagine that the Flags instance is a shared resource in a multi-threaded application. Say thread #1 decides to read the value of Flags->A but thread #2 decides to set or clear Flag->B at the exact same time. How isolated is Flag->A from Flag->B such that any changes to Flag->B does not affect the value of Flag->A? In other words, are set or clear operations in this structure atomic and therefore thread safe?

I looked up the word "plz" in the dictionary and it does not exist, especially not one with that many letter "Z"s.

Note that the question in this thread has already been answered 2 years ago. Why can't you use that code as a starting point?

Just a quick word of advice. It is more efficient to use fwrite() or fputc() instead of fprintf() for writing characters to a file one at a time. This is because fprintf() needs to parse the format string whereas fwrite() and fputc() does not.

This only matters if you plan on dealing with very large files.

Try this:

int Status = system("cmd.exe /c c:/xyz.bat");

Or on Windows 64 bit:

int Status = system("%windir%\\Sysnative\\cmd.exe /c c:/xyz.bat");

I'm not on Windows so I can't test this for you. Can't hurt.


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

I just tested the code and it agrees with Ancient Dragon's explanation. Sorry about that.

Integer has nothing to do with pointer size. The pointer is the size of the memory address as dictated by the Operating System based on the CPU's capabilities. A 32 bit CPU will have a 4 byte address whereas a 64 bit CPU will have an 8 byte address. Some Operating Systems will have an emulation layer that would change this address size.

Be careful assuming the size of the pointer as you will force your software to be locked into specific system specifications. Use this line of code when you need to figure that sort of thing out:

int PointerSizeOnThisSystem = sizeof(char *);

Its funny to think that c=(--a)+(--a); is not any more efficient than --a;--a;c=a+a; in terms of how it compiles. Its just that the first version is ambiguous in design as (--a) acts as a function with a side effect rather than as a variable in an algebraic formula.

Ever since I learned about the ++ operator I felt it was like cheating and could confuse people on this very thing. It would make C much more logical if you avoided ++ altogether in place of inline function calls achieving the same thing.

I'd start over from scratch with this strategy:

  1. Load the entire file into an array of strings. Create a new line for every newline character found. Don't bother with scanning it or doing anything else other than load those lines into memory. If you do this then it lessens the complexity of the code and makes it easier for you to debug it.

  2. Since you are dealing with fixed width if you don't care too much about the data quality then you can simply add NULL characters (0) to specific positions of each line of the loaded file. For instance:

Here is an example of a fixed with file

13  JOHN SMITH     $ 86.20
8   MARY JANE      $112.00
443 RON JOHNSON    $  1.55

The asterisks represent where you will put null characters

13 *JOHN SMITH    *$ 86.20
8  *MARY JANE     *$112.00
443*RON JOHNSON   *$  1.55

So if you do that to each line in strategic places now you can access each field like this:

typedef struct {
    char *Field;
} FieldObject;

typedef struct {
    FieldObject Fields[3];
} LineObject;

typedef struct {
    char *Line;
} BufferedFileObject;

LineObject         Lines[3];
BufferedFileObject LoadedFile[3];

// Load Fields into structures
int i = 0;
for (;i<3;i++) { // Per line
    Lines[i].Fields[0].Field = &LoadedFile[i].Line[0];
    Lines[i].Fields[1].Field = &LoadedFile[i].Line[4];
    Lines[i].Fields[2].Field = &LoadedFile[i].Line[19];

// Now you can access each field this way
printf("%s\n", Lines[1].Fields[2].Field); // Prints "MARY JANE     "

Note that this only works if the fixed width field allows for at least one character of space ...

I'm curious if your shell is merely echoing commands to another shell. What does this shell do with the commands it receives? Are they translated into a system API or some library?

Knowing this would help in deciding the best way to manage the command history.

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

This is a great resource:

Pseudo code, Flow charts, etc are nothing more than a human legible medium to stage the logic so that it can then be translated into code.

For instance you can translate this human readable line...

Ask the user for a floating point number

into this code...

printf("Prompt: ");
scanf("%f", &Variable);

The nice thing about pseudo code is that it can be as general or detailed as you want. Its up to you to decide how to translate it to code. Equally nice about simple algebra like you are doing is that it translates very well into programming. More complex formulas may involve writing functions to facilitate specific aspects of the procedure, but that is not something you usually think about in the flowchart / pseudo code process.

I guess you could think of it like a language translation between English to Computer.

I will disagree with Acient Dragon on this one. DOSBox runs native DOS games pretty well, so you have to ask youself "what am I doing differently than these other DOS programs"? I haven't programmed in DOS in forever so I can't say exactly whats wrong, but to just give up due to the platforms age alone is rather pessimistic.

I personally would try to create a very basic graphic program first to see what graphic modes are supported by the emulator, then use that code as a template for your other graphics program. You might also try asking DOSBox forums and mailing lists, or look at the DOSBox documentation to see if there are any clues that would tell you what you might be doing wrong.

A true hacker never gives up. Good luck.

I would classify your question a platform specific issue since again the definition of SOCKET is not your responsability. As the programmer of the PIC32 and user of your compiler you need to have certain expectations of compliance with the standard libraries as perscribed by the C standard. If there are bugs with its functionality thats the platform's fault, not yours.

Unless of course you are not including the correct libraries as defined in your platform documentation. You could always try this and see what happens:

#include <socket.h>

This is illegal unless you are working on an embedded system or a very low tech system that only works with 1 byte addresses:

typedef BYTE SOCKET;

And unless you are reinventing the wheel you should not be actually defining a typedef for SOCKET. Its defined in your socket library headers. In Windows its winsock2.h and linux its sys/socket.h. Find out which is right for your system. You are not responsible for defining this structure unless you are correcting a conflicting definition which a situation you want to avoid as much as you can for scalability sake.

Long story short just include the correct header. The compiler error you mentioned implies that you are not.

Correction: The fix appears to be that I need to use the extern keyword instead of static, then declare it in a CPP file. The problem seems to be with the structure being created in different contexts or address spaces for each loaded CPP file or something. Might be a Borland C++ Builder specific issue.

I fixed the problem by changing line 13 of my main posted code to this:

static _Stock Stock;

Do keep in mind that my actual code is composed of literally thousands of lines of code spanning many cpp/h files. Apparently Borland C++ Builder 5 does not like working with structures defined in headers unless its anchored down with the static keyword.

I guess thats good information.

In this case its being called by a VCL button OnClick event handler. The code itself is in a cpp file compiled with the rest of the project. As an event handler, I doubt it is a constructor.

How would that matter?

Thank you for your quick reply deceptikon. The problem with your theory is that the TempPage variable worked fine using malloc(). The problem appears to be in copying the pointer to the actual Stock.Page pointer. Also, I use malloc() in other places of the code (such as creating space for strings and arrays) and that works fine.

Other parts of the code work fine in the C++ compiler. So far this seems to be the main incompatibility.

By the way, you are right about the casting issue. I mistyped the code in my post. It was actually more like this in my real world example:

AnObject *CreateInstance() {
    return (AnObject *)malloc(sizeof(AnObject));

I am importing some C code into a C++ compiler, specifically Borland C++ Builder 5. I seem to have a problem with this style of code:

// A structure that contain's itself
typedef struct AnObject AnObject;

struct AnObject {
    AnObject *Object;

// A global structure to store a pointer of the AnObject structure
typedef struct {
    AnObject  *Page;
} _Stock;

_Stock Stock;

// A function that returns an instance of AnObject
AnObject *CreateInstance() {
    return malloc(sizeof(AnObject));

// A function that copies the generated instance to the global pointer
void somefunct() {
    // The pointer will start off NULL
    Stock.Page = NULL;

    // The pointer should now receive a non-NULL pointer
    Stock.Page = CreateInstance();

In GCC, the Stock.Page pointer will be non-NULL at the end of the somerfunct() function. This is not the case for Borland C++ Builder 5. In that case Stock.Page continues to be NULL.

On the other hand, if I change somefunct() to this...

void somefunct() {
    // The pointer will start off NULL
    Stock.Page = NULL;

    // Borland C++ Builder 5 likes this syntax. TempPage is a non-NULL.
    AnObject *TempPage = CreateInstance();

    // But I still cannot copy the pointer from TempPage.
    Stock.Page = TempPage;

    // Stock.Page is still NULL at this point!

Since I am better versed in the C language, I am thinking that this is some kind of incompatibility with the language itself, and that I need to do this more C++ style. On the other hand, the compiler I ...

Next time you post code, use the [ CODE ] Tags.

The code you posted is terrible. Not only is it highly inefficient but the variable names are undescriptive and there are no comments anywhere to be found.

Either way, the "count" variable is apparently used to store the number of digits in the given number. It seems to follow [URL="

Well, a logic circuit simulator is not a terribly difficult project. I would approach it by creating a generic gate structure containing two gate structure pointers as inputs (assuming thats how many inputs you need), an enum with all the supported gates to define that structure, a function that accepts that structure's pointer as a parameter which simulates its function and returns the output of the gate logic as an integer... Something like this
// Types of gates supported
typedef enum {
} GateType;

// Define a named typedef for our linked list structure
typedef struct GateObject GateObject;

// Define a gate object type
struct GateObject {
GateObject Input_A;
GateType Type;

// A recursive function that simulates the behavior of a single gate
int ProcessGate(GateObject *in_Gate) {
if (in_Gate == NULL)
return 0;
switch (in_Gate->Type) {
case AND_GATE: return ProcessGate(in_Gate->Input_A) & ProcessGate(in_Gate->Input_B);
case OR_GATE: return ProcessGate(in_Gate->Input_A) | ProcessGate(in_Gate->Input_B);
case NAND_GATE: return !(ProcessGate(in_Gate->Input_A) & ProcessGate(in_Gate->Input_B));
case NOR_GATE: return !(ProcessGate(in_Gate->Input_A) | ProcessGate(in_Gate->Input_B));
case POWER: return 1;
return 0;
You probably need to only test the last gate attached to the output line for an accurate answer. This is just a rough estimate of what you need. Build upon it and see where it takes you. You are more than welcome to post what you have so-far and get more help along the way.

[B]now three variables we printed to a file received from the user. This variable to another file, the user wants to take that file and the value of the variable is a variable, you need to do. And this event is the first change the variables in the file must be changed. How can we do? [/B]

This is probably the worst grammar I have read in a long time. But in an effort to help beyond the barriers of the spoken language, I will attempt to repair your grammar and restate your question. I will use square brackets to indicate words added and parenthesis to indicate words replaced:

[B]Now, [there are] three variables [that] (my program) print(s) to a file from user [input]. (These) variable['s] (in that file must be copied to) another file, (but here is what) (I) need to do: First, (I must) change the variables in the (first) file (before copying it to the second file). How can (I) do (this)?[/B]

Well [B]engineer61[/B], I'm not sure what this has to do with a [I]linklist[/I] as your subject described, but why can't you just write to the two files from the user input instead of writing to one of them and then reopening that one to modify it to create a second one? It almost sounds like you need to make two separate programs. Can you elaborate?

If you have any specific questions from the book, you should ask them here. We would be happy to help you. It is not the nature of DaniWeb to give out answers, especially instructor's manuals.