Solved

Help with variables...

Posted on 2006-11-06
4
166 Views
Last Modified: 2010-04-24
I'm having issues with variables...

I am trying to load some configuration information from a text file and use it elsewhere in my application.

Here are snipets from the code:

char * CIP = "000.000.000.000";
char* IpAddress = CIP;

errno_t err;

if ((err = fopen_s(&instream, "config.txt", "r")) != 0)
{
      Memo1->AppendText("Configuration file failed to open.\r\n");
}
else
{
      Memo1->AppendText("Configuration file successfully opened.\r\n");
                        
      fscanf(instream, "%s\n", CIP);
}

I am getting an "attempted to read or write to protected memory" error when compiling. I know this has to do with pointers and such, but I've never been good with them and I'm stumpted on this one.

I am not able to change the CIP decleration or usage as the other 2000 lines of code work with it as it is. What I need is the read the first line of the text file and then assign that information to the CIP variable.

Any help you be appreciated as this problem is urgent...
0
Comment
Question by:demilune
  • 3
4 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 500 total points
ID: 17887330
Hi demilune,

Change char * CIP = "000.000.000.000";
to
char CIP[] = "000.000.000.000";

String literals are often stored in read only memory ... by declaring it as array, you would be storing it in R/W memory (stack if declarede locally and data segment if declared globally)

Cheers!
sunnycoder
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17887333
>I am not able to change the CIP decleration or usage as the other 2000 lines of code work with it as it is.
This change should not affect your existing code. ... give it a shot
0
 

Author Comment

by:demilune
ID: 17887346
THANKS THANKS THANKS...

I knew I was missing something simple like that. I had not realized literals were stored read only.

Thanks again!
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 17887435
Glad to help :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now