Hallo, Is it possible, that I can add the strings '1' '.' and '2'. I want to add this 3 strings: 1.2 and convert it into a float value and than I want add a float value.
Usually, the appropriate library functions can be found in string.h (strcat() ) and stdlib.h (atof() ).
No. I only can cut, copy or compare strings but I can not add them. d = a + b + c; e = (float) d; The compiler convert all char into ASCII numbers. I need e = 1.5 and no ASCII nuber.
I think you need to go back to basics, and think about what a string actually is.
A string could be something like "apples" or "oranges" - so how could you meaningfully compute a sum of those?!
The nearest thing would be to concatenate them; eg,
string1 := "apples" string2 := "oranges" string3 := string1 + string2 -- gives "applesoranges"
If your strings represent numbers, then you first need to convert them into numerical values.
Look-up the standard 'C' library, or write your own custom function to convert between strings and numbers...
My problem is: I get form the MDU 2 components. One component before and on after the comma. I must add them to a float value. Example: before: 5 after: 2 The value of my division is 5.2. I need this value. Idea: I convert these two values and add them with a comma to a string value. That works but if I want to convert this string back to a float value, the compiler converts the comma into an ASCII sign.
Have you even looked at the descriptions of the two functions I mentioned ?
You cannot "add" strings (at least in C. Maybe in BASIC or something). You concatenate them. That's what strcat() (from string.h) does.
atof() converts a string to a floating point number.
"My problem is"
Your problem is that you have still not understood the nature of a string, and the difference between strings and numerical values.
"I get form the MDU"
What is an "MDU"?
A string is, by definition, for text - in C251, that means ASCII-coded characters.
To do arithmetic, you need numerical values such as int or float.
Standard library functions exist to convert between strings & numerical values - look them up! Alternatively, write your own.
View all questions in Keil forum