C language problems-General Linux technology-Linux technology and application information, the following is a detailed description. Question: enter two time points (in the 24-hour format) on the keyboard and output the time interval between the two time points. The time interval is represented by "hour: minute: Second.
Source code compiled by myself:
# Include
# Include
Int main (void)
{
Struct time {
Int h;
Int m;
Int s;
} Gap;
Int gapsec;
Int get_sec (void );
Gapsec = get_sec ();
Gapsec-= get_sec ();
Gap sec = (gap SEC> = 0 )? Gap SEC:-gap SEC;
Gap. h = gap SEC/3600, gap SEC % = 3600;
Gap. m = gap SEC/60, gap SEC % = 60;
Gap. s = gapsec;
Printf ("% d: % d \ n", gap. h, gap. m, gap. s );
Return 0;
}
Int get_sec (void)
{
Int I, j, totalsec = 0;
Char a [20], h [5], m [5], s [5], c;
For (I = 0; (c = getchar ())! = '\ N'; I ++)
A
= C; A= '\ 0 '; For (I = 0, j = 0;! = ':'; I ++, j ++) H [j] =; H [j] = '\ 0 '; Totalsec = atoi (h) * 3600; For (I ++, j = 0;! = ':'; I ++, j ++ ); M [j] =; M [j] = '\ 0 '; Totalsec + = atoi (m) * 60; For (I ++, j = 0;! = '\ 0'; I ++, j ++ ); S [j] =; S [j] = '\ 0 '; Totalsec + = atoi (s ); Return totalsec; }
Problem: This code can be compiled on 64-bit ubuntu (12.04), but when debugging through gdb, the arrays m and s in the get_sec function cannot write the corresponding data, and the results are very strange, which of the following is my hope!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service