?
Solved

Help with variables...

Posted on 2006-11-06
4
Medium Priority
?
173 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
[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
  • 3
4 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

719 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