『壹』 c語言,如何在按某個鍵的時候刷新屏幕
#include<stdio.h>
#include<conio.h>
main()
{
chara;
printf("pressaclearscreen");
while(1)
{
a=getch();
if(a=='a')
{
system("cls");
}
}
}
『貳』 用c語言編寫一個網頁刷新器
只要一直發送請求,之後再斷開,反復就可以了,間隔時間就是設在循環中,刷新次數用循環控制。
『叄』 這個C語言打磚塊的代碼,磚塊如何實現刷新(磚塊怎麼消失)
c語言游戲中實現動畫靠的是1秒鍾多於25次的刷新。大一用easyx做過類似的,現在有點忘了,核心思想大概是
while(判斷游戲未結束)//時間沒停,未觸發游戲終止標志
{
for(inti=0;i<objectNum;i++)
{
//根據時間更新每個磚塊的狀態
//如果某磚塊的flag設為被打到,清除該物品,如果是鏈表刪節點
//未被打到,磚塊.y更新
}
//畫背景圖
for(inti=0;i<objectNum;i++)
{
//畫每個磚塊
}
//獲取用戶命令
//一旦有命令,DispatchCommand()
//調用那個函數,檢測滑鼠位置停留的時候是不是按鍵了,檢測有沒有操作磚塊
//sleep(100ms),延時造成視覺停留
}
『肆』 C語言中怎樣在統計字元時即時刷新
使用getch();函數, 接收字元竄, 不需要按回車鍵
返回的是輸入的字元
頭文件為 conio.h
『伍』 C語言中可不可以對部分數據刷新(清屏),而不是全部清屏
老的16位的PC是可以的,有函數在黑窗第幾行第幾列定位寫輸出。
現在的辦法是建一個數據表,固定相對位置輸出數據,清屏幕一次,全部重寫(更新)一次,數值變的重寫,數值不變的也重寫一遍,就達到「部分數據刷新"
例如下面時間更新程序,變秒。。。,變分。。。
#include<stdio.h>
#include<time.h>
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
int main ()
{
time_t rt;
struct tm *t;
long int i;
for (i=0;i<3600;i++)
{
time ( &rt );
t = localtime ( &rt );
system("cls");printf("\n\n\n\n\n\n\n\n\t");
printf ( "Year: %d ", t->tm_year+1900 );
printf ( "Month: %d ", t->tm_mon +1 );
printf ( "day: %d ", t->tm_mday);
printf ( "hour: %d ", t->tm_hour);
printf ( "minute: %d ", t->tm_min);
printf ( "second: %d\n", t->tm_sec);
wait (1);
}
return 0;
}
-------
視窗編程,當然可以在任何位置輸出和「清屏」,我猜你問的是DOS cmd 窗.
『陸』 c語言怎麼刷新輸出時間
由於c語言標准庫函數,沒有Sleep延時程序,需要自己編寫,主要通過循環判斷difftime函數返回的時間差來實現延時,具體代碼如下,
#include <stdio.h>
#include <time.h>
//延時程序
void sleep(int s)
{
time_t tmp1=time(NULL);
time_t tmp2=tmp1;
while(difftime(tmp2,tmp1)<s)//延時s秒後結束
{
tmp2=time(NULL);
}
}
int main(int argc, char *argv[])
{
int i=1;
while(i)
{
printf ("%d : %s \n",i++,__TIME__);//列印i及程序編譯時間
sleep(1);
system("cls"); //清屏
}
return 0;
}
函數double difftime(time_t time2, time_t time1);返回兩個time_t型變數之間的時間間隔,即 計算兩個時刻之間的時間差。time1計時開始時間,time2計時結束時間,不斷更新time2直至(time2-time1)為所需要的延時時間即可。
『柒』 C語言中寫入數據怎樣才可以刷新寫入謝謝!~
你好!!
不知你向文件輸入的是什麼數據,輸入數據的函數很多,有fputc(s,fp);有fwrite()函數、、、、
下面是想文件輸入字元,並把字元串中的小寫字元轉換成大寫字元:
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
FILE *fp;
char filename[20];
printf("請輸入文件的名稱:");
scanf("%s",filename);
if((fp=fopen(filename,"w"))==NULL)
{
printf("cannot open file !!!\n");
exit(0);
}
printf("請輸入字元直至結束(ctrl +z):");
fflush(stdin);
char s;
while(scanf("%c",&s)!=EOF)
{
if(islower(s))
s=toupper(s);//把小寫字元轉換成大寫字元
fputc(s,fp);
}
rewind(fp);//是位置指針重新返迴文件的開頭,此函數沒有返回值
if((fp=fopen(filename,"r"))==NULL)//以讀的方式打開文件
{
printf("cannot open file !!!\n");
exit(0);
}
while(!feof(fp))
{
s=getc(fp);
putchar(s);
}
return 0;
}
測試:
請輸入文件的名稱:hello
請輸入字元直至結束(ctrl +z):hello world !
Z
Z
HELLO WORLD !
Press any key to continue
『捌』 c語言怎麼實現一個數,每天刷新一次,我做簡單的彩票系統,用了隨機數開獎。雙色球,怎麼讓他每天開獎(
如果只是簡單的產生隨機數很簡單,但是如果你要求隨機數每天都在刷新的話,那麼這個程序需要運行在一個平台上面,並且這個平台可以提供時間,方便的話可以把要求說的再詳細一些.
『玖』 如何用c語言編寫一個程序,功能是循環對一個網頁進行刷新,然後對提示的信息選擇確定按鈕,求代碼,謝謝
//CreateList_L.cpp
//To create a LinkList
#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
# define TRUE 1
# define FALSE 0
# define OK 1
# define ERROR 0
# define INFEASIBLE -1
# define OVERFLOW -2
typedef struct DuLNode
{ int data;
struct DuLNode *prior;
struct DuLNode *next;
}DuLNode,*DuLinkList;
// 初始條件:L已存在。操作結果:返回L中數據元素個數
int ListLength(DuLinkList L)
{
int i=0;
DuLinkList p=L->next; // p指向第一個結點
while(p!=L) // p沒到表頭
{
i++;
p=p->next;
}
return i;
}
// 由雙鏈循環線性表L的頭結點出發,正序輸出每個數據元素
void ListTraverse(DuLinkList L)
{
DuLinkList p=L->next;
while(p!=L)
{
cout<<p->data<<"\t";
p=p->next;
}
cout<<endl;
}
// 由雙鏈循環線性表L的頭結點出發,逆序輸出每個數據元素
void ListTraverseBack(DuLinkList L)
{
DuLinkList p=L->prior;
while(p!=L)
{
cout<<p->data<<"\t";
p=p->prior;
}
cout<<endl;
}
//To Creatre a DuLinkList L with HeadNode
void CreateList_DuL(DuLinkList &L)
{
int n;
int i;
DuLNode *p;
L=(DuLinkList)malloc(sizeof(DuLNode));
L->next=L->prior=L;
cout<<"CreateList_L"<<endl<<"================"<<endl;
cout<<"Please input the Init DuLinkNode Number: <eg. 5> ";
cin>>n;
cout<<"Please input the data for DuLinkList Nodes: <eg. 34,67,3,-9,45,...>"<<endl;
for(i=n;i>0;--i)
{
p=(DuLinkList)malloc(sizeof(DuLNode));
cin>>p->data; //Reverse order inputing for Creating a LinkList
p->prior=L;
p->next=L->next;
L->next->prior=p;
L->next=p;
}
if(n)
{
cout<<endl;
cout<<"Success to Create a DuLinkList !"<<endl;
ListTraverse(L);
cout<<endl;
}
else cout<<"A NULL DuLinkList have been created !"<<endl;
}
//ListInsert_Dul()
int ListInsert_DuL(DuLinkList &L)
{
DuLNode *p=L,*s;
int j=0;
int i;
int e;
cout<<"======"<<"before insert:"<<"======"<<endl;
ListTraverse(L);
cout<<"input the location you want to insert:";
cin>>i;
while (i<1||i>ListLength(L)+1)
{
//i值不合法
cout<<"illeagle location,please input the correct location:";
cin>>i;
}
cout<<"input the number you want to insert:";
cin>>e;
while(j<i)
{ p=p->next;
++j;
}
if(!(s=(DuLinkList)malloc(sizeof(DuLNode))))
{
cout<<endl<<"Allocate space failure ! " ;
return (ERROR);
}
s->data=e;
s->prior=p->prior;
s->next=p;
if(i==1)
L->next=s;
p->prior->next=s;
p->prior=s;
cout<<"has insert:"<<e<<endl;
ListTraverse(L);
cout<<"======"<<"after insert:"<<"======"<<endl<<endl;
return (OK);
}
// 刪除帶頭結點的雙鏈循環線性表L的第i個元素,i的合法值為1≤i≤表長
int ListDelete(DuLinkList L)
{
DuLinkList p;
int j=1; // j為計數器
int e;
int i;
cout<<"input the location of the number you want to delete"<<endl;
cin>>i;
while(i<0||i>ListLength(L))
{
//i值不合法
cout<<"illeagle location,please input the correct location:";
cin>>i;
}
p=L->next; // p指向第一個結點
while(p!=L&&j<i) // 順指針向後查找,直到p指向第i個元素或p指向頭結點
{
p=p->next;
j++;
}
if(p==L||j>i) // 第i個元素不存在
{
cout<<"第i個元素不存在"<<endl;
return ERROR;
}
else
{
cout<<"======"<<"before delete:"<<"======"<<endl;
ListTraverse(L);
e=p->data; // 取第i個元素
if(!p) // p=NULL,即第i個元素不存在
return ERROR;
e=p->data;
p->prior->next=p->next;
p->next->prior=p->prior;
free(p);
cout<<"has delete:"<<e<<endl;
ListTraverse(L);
cout<<"======"<<"after delete:"<<"======"<<endl<<endl;
return OK;
}
}
void menu(int c)
{
cout<<"================================================="<<endl;
cout<<"\t\t1----建立"<<endl;
cout<<"\t\t2----插入"<<endl;
cout<<"\t\t3----刪除"<<endl;
cout<<"\t\t4----逆置"<<endl;
//cout<<"\t\t5----菜單"<<endl;
cout<<"\t\t0----退出"<<endl;
cout<<"================================================="<<endl;
cout <<endl<<"input you choice number:";
}
void main()
{
DuLinkList L;
int c=1;
while(c!=0)
{
switch(c)
{
case 0:
break;
case 1:
CreateList_DuL(L);
break;
case 2:
ListInsert_DuL(L);
break;
case 3:
ListDelete(L);
break;
case 4:
ListTraverseBack(L);
break;
default:
cout<<"infeasible choice,input again:"<<endl;
menu(c);
cin>>c;
}
if(c!=0)
{
menu(c);
cin>>c;
}
}
}