Solved

# defined memory location

Posted on 2003-11-03
4
247 Views
Last Modified: 2010-04-17
Hi, Can any of u tell me how i can define the memory location for the files that i create, using "# define" statement?? I have to create a list of files and i need to store them in a specified location. I have to speicfy that location using "# define" so that, if i want to change the storage location at one point, i just have to change the "# defined location". If u can explain with an example, it would be very nice of you.
0
Comment
Question by:motian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9670154
Hi motian,

AFAIK this is not possible in C
you cannot pre determine which memory location will be assigned to you by the compiler
all these abstractions are anyway handled by using variables.... why do you want to override compilers handling of memory ?

If you can specify what you are trying to achieve, we may be able to help you better

Cheers!
Sunny:o)
0
 

Author Comment

by:motian
ID: 9670260
Hi,
  Thank you for such a fast reply. I have made a mistake in my question. I meant the "hard disk storage" by saying, memory location.If i don't specify the disk in which my files should be stored,it goes to the default place of where my code resides.
 I don't want it that way but want to specify a desired disk(say D:\) while my code is in the C drive.And i should also be able to change it by just altering the "# define" statement. Hope you get my problem right,now.
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 30 total points
ID: 9670302
in that case, just #define the target drive/directory

#define LEAD_PATH D:\

whenever you wish to create/save a file add LEAD_PATH prefix to filename !!!
0
 

Expert Comment

by:kcy
ID: 9676124
I beg to differ slightly from sunnycoder,

If you try to put LEAD_PATH in quotes when you use it then you would not get the value it defines but the string "LEAD_PATH" instead.

I believe that this will work better:

#define LEAD_PATH "D:\\"   /* note: two slashes are necessary because a backslash is used for control characters in a string*/

and it would be used like this for instance:

fp = fopen(LEAD_PATH"morepath\\myfile.txt", "r");

This gets converted to by the preprocessor to:

fp = fopen("D:\\""morepath\\myfile.txt", "r");

and finally to:

fp = fopen("D:\\morepath\\myfile.txt", "r");

FYI: You CAN create a #define to access a memory location directly in C.  This is useful in embedded applications where you control the memory map.  It would look something like this:

#define MYMEM ((char*)(0x000F0000))   /* Where the location 0x000F0000 contains the start of the string "TEST" */

to use:

printf ("Third char is %c, Memory contains %s\n", MYMEM[2], MYMEM);

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Identify two keyboard codes and how to enter them 9 70
Java List 4 42
Oracle programming for starter 14 37
How to delete text box content on subform 1 22
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question