Solved

Help with variables...

Posted on 2006-11-06
4
171 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 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

627 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