?
Solved

comparing 2 values

Posted on 2006-11-30
4
Medium Priority
?
201 Views
Last Modified: 2010-04-15
I need to compare an analog to digital converter (ADC) result which is stored as a char with a floating double. I need to convert the ADC result to make it the same type before compareing in C code.

thanx
0
Comment
Question by:Marlien
[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
4 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 2000 total points
ID: 18044178
Hi Marlien,

> stored as a char with a floating double
perhaps you meant double stored as a string ...
If yes, then you can use atod() or strtod() for converting the string to double
http://www.cplusplus.com/ref/cstdlib/strtod.html
Only note about the example at the above link - dont use gets ... use fgets instead!

http://www.opengroup.org/onlinepubs/000095399/functions/strtod.html

Cheers!
sunnycoder
0
 
LVL 11

Expert Comment

by:cup
ID: 18059260
With the ADC, you normally get some margin of error.  You will probably not get an exact value so it is worth range checking.

Most ADCs I've worked with only return integers and I have to go through some conversion routine to get it to a double.  The tolerance range is one unit of the integer range.
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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

764 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