0
所以我得到了我需要做的關於製作數字時鐘的工作。 用戶設置點頭的數目和每個點頭是具有第二1/n,其中N是點頭的數量相等,我稱爲用戶puts.After使3個指針:使用循環鏈表作爲時鐘的問題
- 一個用於秒
- 一個用於分鐘
- 一個小時
秒指針必須運行在圓形鏈接所有的點頭。對於完整的旋轉,分鐘的指針應該開始移動到下一個節點,並且在總共60次移動分針後,小時指針應該緊跟在後面。 時鐘需要做以下的事情:
用戶可以設置時鐘回零:00:00;
用戶可以以秒爲精度設置時鐘。
程序需要在每次活動後顯示時鐘。
用戶可以編程鬧鐘的時鐘,在鬧鐘中時鐘向用戶顯示一條消息。
它需要找到下一個小時,它的指針(時鐘不是程序)獲得一致(例如:12:00,01:05,02:10.03:15等)
- 在釋放我們的列表所用的任何內存後,它完成程序。
這是我的代碼,但我遇到了一些困難。
#include<stdio.h>
#include<stdlib.h>
int counter=0;
typedef struct Node
{
int data;
struct Node *next;
}node;
void insert(node *pointer, int data)
{
node *start = pointer;
/* Iterate through the list till we encounter the last node.*/
while(pointer->next!=start)
{
pointer = pointer -> next;
}
/* Allocate memory for the new node and put data in it.*/
pointer->next = (node *)malloc(sizeof(node));
pointer = pointer->next;
pointer->data = data;
pointer->next = start;
}
void print(node *start,node *pointer)
{
if(pointer==start)
{
return;
}
printf("%d ",pointer->data);
print(start,pointer->next);
}
int main()
{
/* start always points to the first node of the linked list.
temp is used to point to the last node of the linked list.*/
node *start,*temp;
start = (node *)malloc(sizeof(node));
temp = start;
temp -> next = start;
/* Here in this code, we take the first node as a dummy node.
The first node does not contain data, but it used because to avoid handling special cases
in insert and delete functions.
*/
node *sec,*min,*hour;
int v,c,n;
printf("1. Insert N\n");
printf("2. Make Time Zero\n");
printf("3. Set Clock\n");
int query;
scanf("%d",&query);
if(query==1)
{
int data,i,n;
printf("Posa n thes\n");
scanf("%d",&n);
for (i = 0; i < 60*n; i++)
{
data = i;
insert(start,data);
printf("%d\n",i);
}
node *sec_copy;
sec_copy=start;
min=start;
hour=start;
while(n>0)
{
sec_copy=sec_copy->next;
n--;
c++;
if(c == 59*n)
{
min=min->next;
c=0;
v++;
}
if(v == 60)
{
hour=hour->next;
v=0;
}
}
}
printf("%d",sec->data);
if(query==2)
{
int timer;
timer=0;
printf("%.2d:%.2d:%.2d",timer,timer,timer);
}
if(query==3)
{
int h,m,s;
printf("Set me hours");
scanf("%d",&h);
h = h%24;
printf("Set me min");
scanf("%d",&m);
h = h+m/60;
m = m%60;
printf("Set me secs");
scanf("%d",&s);
h = h + s/3600;
m = m + s%3600;
s = s%60;
}
}
時間(雙關不打算)學習如何使用調試器。使用調試器,您可以逐行瀏覽程序,並觀察變量的值。這將幫助你瞭解真正發生的事情。 – 2014-11-05 10:38:05
'我遇到了一些困難' - 你能不能更模糊? – 2014-11-05 10:39:17
@MartinJames它說段落故障核心傾銷後,我做了一些編輯。 – Andreakos 2014-11-05 10:43:13