"unix_Time is a long variable to save te sum of the operation but, the operation in part 3 the result is wrong because don´t make the rest of one."
I do not understand " because don´t make the rest of one" ?
Also not seeing the variable definitions, and a description of what the code is supposed to do
difficult to help you.
Im sorry for the bad explanation, Im trying to do a function that convert the time an date in unix time, first I convert the years, months in days and then convert the days to second and then convert hour and minute in second the sum of all days in seconds and hour, minute in seconds give me the unix time. the hour, year, month are ASCII so I convert in integer using atoi, when I made the operation unix_Time +=atoi(dia)-1 the resul is wrong for example
unix_Time = 16190
dia = '5' in ASCII
unix_Time += atoi(dia) - 1;
16190 + 5 - 1 = 16194 <------- this is the correct anwers
I get 16195 as if he had not made the subtraction by least 1 then I multiply this value by 86400 but the result also is wrong
Your error is not in the math, althoug I found an easier algorithm in the german-language wikipedia here: de.wikipedia.org/wiki/Unixzeit
The function ultoa() expects at its first parameter a pointer to an array of characters where the resulting string has to be stored. You provide a pointer variable, but it is not initialized to point to a valid memory area. Better is to define your var as
char unixTime; // Allocates space for a string with 10 chars and a null at the end
ultoa(unixTime,unix_Time,10); // conversion
Some additional comments -
1) You do not use logical pin names for the pins. You can type them/
rename them in pin editor. Makes it easier to understand functionality
of the pin. And in pin view understand whats going on.
2) For each module you have a number of parameters not set in its respective
global properties window view. Thats not good practice, could lead to unexpected behaviour
of module, especially if you do not set these with API code.
Thanks bob I use unixTime, but I have wrong result yet when I did math operation in this form:
I could fix the problem, firts save the convertion in a variable and then multiplication:
vTemp= vTemp *3600;
unix_Time += vTemp;
I have another question I read that the result of ftoa have a buffer of 15 bytes how can I do to only display for example 3 digits after of point (12.135 for example).
Switch from atoi() / atof() etc to sprintf(). This gives you full control over formatting the output and leaves the result in a buffer you have to supply. Read this knowledgebase article www.cypress.com/ to see how to switch the on the needed libraries and check out the formatting strings at publications.gbdirect.co.uk/c_book/chapter9/formatted_io.html
You might want to look at this -
Also you might want to file a CASE to see if the above still necessary in Designer
5.4 and that its complete in its functionality -
To create a technical case at Cypress -
“Create a Case”
You have to be registered on Cypress web site first.
Thanks bob and dana I will read it and thanks for your help.