reference 10222290

when reading in a string from an ini file and converting to integers, how do I handle negative integers
jgreavesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
Hmm, what problems do you encounter? The code should be able to handle negative integers...
0
jgreavesAuthor Commented:
you're right, my mistake... the variable in the structure is defined as unsigned16 which is why I was getting strange results.  FYI, modifications from the code you sent me earlier in comments.  thanks for all of your help so far

GetPrivateProfileString(szDrive, "Phase3Vals", NULL, acBuf, MAX_SERCOS_STRING_LEN,  m_strFilename);
pc = strtok ( acBuf, pszDelims);

i = 0;
while ( pc)
{
  // skip the '0x' - the docs say that it's not necessary
  if ( !(pcCnvStart = strchr ( pc, 'x')))
  {
    // found no 'x' in the substring...
    n = (int) strtol ( pc, &pcCnvEnd, 10); // <-- added
  }
  else
  {
    // found an 'x' in the substring, skip it...
    pcCnvStart++;
    n = (int) strtol ( pcCnvStart, &pcCnvEnd, 16); // <-- added
  }
  //n = (int) strtol ( pcCnvStart, &pcCnvEnd, 16); // <--removed

  Drive_IDNs3[i].value = n;
  pc = strtok ( NULL, pszDelims);
  i++;
  }
}
0
nietodCommented:
How are you reading the file?  Most methods I can think of should handle this fine.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

jkrCommented:
Todd, it's an .ini file. The suggested method to read a value containing multiple integers was to read it as a string, break it down with 'strtok()' and converting value by value.
0
nietodCommented:
I know its an ini file.  I was wondering how he could do this and not get signed values.  (Storing the result in an unsigned int is one way--a way that I didn't think of!)    That is why I wanted to know what he was doing to the file.

(Note that At the time that I posted my comment, his explanation of the problem was not visible.)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkrCommented:
What are you going to do with this Q then?
0
nietodCommented:
Well, jkr, I guess, that answers your question.  Of Course it raises the question of why?
0
jkrCommented:
I also thought of asking this particular  Q ;-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.