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
Solved

comparing 2 values

Posted on 2006-11-30
4
193 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
4 Comments
 
LVL 45

Accepted Solution

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

856 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