Solved

comparing 2 values

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to communicate between two pc's through vb.net code ? 4 150
My eclipse editor won't start ? 4 154
Need example 5 113
Super Scope, DHCP 5 75
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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 while-loops in the C programming language.

786 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