Solved

comparing 2 values

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to 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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now