Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need help fast! char MG[3]; MG="400?due" ?

Posted on 1998-01-06
4
Medium Priority
?
184 Views
Last Modified: 2010-04-10
This is the function I am having problem with:

void Les_Inn_Verdier()
{
      char InnBuffer[100];
      unsigned int count=100;
      int fhInn;
        fhInn = _open( "f:\\diplom\\flysim.dat", _O_RDWR |           _O_CREAT, _S_IREAD | _S_IWRITE);
      _read( fhInn, InnBuffer, count );
      _close( fhInn );
      char MG[3];
      char MA[5],MP[4];
      MG[0]=InnBuffer[0];
      MG[1]=InnBuffer[1];
      MG[2]=InnBuffer[2];
      Max_Groundspeed = atof(MG);
      MA[0]=InnBuffer[3];
      MA[1]=InnBuffer[4];
      MA[2]=InnBuffer[5];
      MA[3]=InnBuffer[6];
      MA[4]=InnBuffer[7];
      Max_Altitude = atof(MA);
      MP[0]=InnBuffer[8];
      MP[1]=InnBuffer[9];
      MP[2]=InnBuffer[10];
      MP[3]=InnBuffer[11];
      Max_Pitch = atof(MP);
}

With my buffer, called InnBuffer like this:
InnBuffer = "400;30000;45.0;"
I get this result:
MG = "400?due"
MA = "30000ye"
MP = "45.00210002,d"
I had expectet MG = "400", MA="30000" and MP = "45.0", but that was clearly wishful thinking. I have no idea what can be wrong and really hope someone can help me with this as fast as possible.

0
Comment
Question by:Krafer
[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 22

Accepted Solution

by:
nietod earned 800 total points
ID: 1177654
answer comming
0
 
LVL 22

Expert Comment

by:nietod
ID: 1177655
The problem is that your strings are not NUL termianted.  C (and C++) uses a NUL character (a byte with the value 0) to terminate a string, that is, to indicate the end of the string.  You need to declare your strings with enough space to have the terminator and you need to set the terminator.  You need to do something like.

char MG[4]; // room for 3 characters and a terminator.
MG[0]=InnBuffer[0];
MG[1]=InnBuffer[1];
MG[2]=InnBuffer[2];
MG[3]=0; // terminate.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1177656
Same sort of logic applies to the other strings (character arrays).

Hope that is fast enough.
0
 

Author Comment

by:Krafer
ID: 1177657
That was impressingly fast! And of course the answer was correct. I was just about to start working my way around the problem, and that would probably have taken hours.

The chances that I get this diploma finished in time has increased.

Thanks!

Norwegian student

0

Featured Post

Industry Leaders: 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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

636 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