Solved

comparing 2 values

Posted on 2006-11-30
4
196 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 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

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

717 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