當前位置:首頁 » 編程語言 » c語言fdset

c語言fdset

發布時間: 2025-07-26 07:29:03

1. VC環境中用c語言查找當前路徑下的所有文件和文件夾的函數是什麼

這是我的TFTP程序中的一個函數,是搜索當前盤符下的所有文件,包括文件的大小,並發送到客戶端,其中就有查找當前路徑下的文件,你自己挑一下,應該能完成你的需求。
void FileList(sockaddr_in sour_addr,char strStartDir[])
{
char sendbuffer[1024];
sockaddr_in destaddr;

int sourlen = 0;
int ret = 0;
int len = 0;
int flen = 0;

fd_set fdr;

unsigned short blocknum = 0;

FILE *file;
char filename[128];

strcpy(filename,strStartDir+2); /*獲取文件名*/

strcat(filename,"\\*");
destaddr.sin_family = AF_INET;
destaddr.sin_port = sour_addr.sin_port;
destaddr.sin_addr.s_addr = inet_addr(desthost);//

WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(filename, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
printf ("Invalid File Handle");
}
else
{
while(FindNextFile(hFind,&FindFileData))
{
printf(FindFileData.cFileName);
printf("\r\n");
memset(sendbuffer,'\0',1024);

len = filldata(blocknum++,FindFileData.cFileName,strlen(FindFileData.cFileName),sendbuffer,sizeof(sendbuffer));
ret = sendto(serverSock,sendbuffer,len,0,(sockaddr *)&destaddr,sizeof(destaddr));

}
len = fillover(blocknum,"Over",4,sendbuffer,sizeof(sendbuffer));
ret = sendto(serverSock,sendbuffer,len,0,(sockaddr *)&destaddr,sizeof(destaddr));
FindClose(hFind);
return;
}
}

2. 如何用C語言寫貪吃蛇

#include<conio.h> #include<graphics.h> #include<time.h> #include<string.h> #include<malloc.h> #include<stdio.h> int grade=5,point=0,life=3; void set(),menu(),move_head(),move_body(),move(),init_insect(),left(),upon(),right(),down(),init_graph(),food_f(),ahead(),crate(); struct bug { int x; int y; struct bug *last; struct bug *next; }; struct fd { int x; int y; int judge; }food={0,0,0}; struct bug *head_f=NULL,*head_l,*p1=NULL,*p2=NULL; void main() { char ch; initgraph(800,600); set(); init_insect(); while(1) { food_f(); Sleep(grade*10); setcolor(BLACK); circle(head_l->x,head_l->y,2); setcolor(WHITE); move_body(); if(kbhit()) { ch=getch(); if(ch==27) { ahead(); set(); } else if(ch==-32) { switch(getch()) { case 72:upon();break; case 80:down();break; case 75:left();break; case 77:right();break; } } else ahead(); } else { ahead(); } if(head_f->x==food.x&&head_f->y==food.y) { Sleep(100); crate(); food.judge=0; point=point+(6-grade)*10; if(food.x<30||food.y<30||food.x>570||food.y>570) life++; menu(); } if(head_f->x<5||head_f->x>595||head_f->y<5||head_f->y>595) { Sleep(1000); life--; food.judge=0; init_graph(); init_insect(); menu(); } for(p1=head_f->next;p1!=NULL;p1=p1->next) { if(head_f->x==p1->x&&head_f->y==p1->y) { Sleep(1000); life--; food.judge=0; init_graph(); init_insect(); menu(); break; } } if(life==0) { outtextxy(280,300,"游戲結束!"); getch(); return; } move(); }; } void init_graph() { clearviewport(); setlinestyle(PS_SOLID,1,5); rectangle(2,2,600,598); setlinestyle(PS_SOLID,1,1); } void set() { init_graph(); outtextxy(640,50,"1、開始 / 返回"); outtextxy(640,70,"2、退出"); outtextxy(640,90,"3、難度"); outtextxy(640,110,"4、重新開始"); switch(getch()) { case '1': menu();setcolor(GREEN);circle(food.x,food.y,2);setcolor(WHITE);return; case '2': exit(0);break; case '3': outtextxy(700,90,":1 2 3 4 5");grade=getch()-48;set();break; case '4': food.judge=0,grade=5;point=0;life=3;init_insect();menu();break; default: outtextxy(250,300,"輸入錯誤!"); set();break; } } void menu() { char str[20],str1[]={"分數:"},str2[]={"難度:"},str3[]={"生命值:"}; init_graph(); sprintf(str,"%d",point); strcat(str1,str); outtextxy(640,50,str1); sprintf(str,"%d",grade); strcat(str2,str); outtextxy(640,70,str2); sprintf(str,"%d",life); strcat(str3,str); outtextxy(640,90,str3); outtextxy(640,110,"設置:ESC"); } void init_insect() { head_f=(struct bug *)malloc(sizeof(struct bug)); head_f->last=NULL; head_f->x=300; head_f->y=300; p2=head_f->next=p1=(struct bug *)malloc(sizeof(struct bug)); p1->last=head_f; p1->x=295; p1->y=300; p1=p1->next=(struct bug *)malloc(sizeof(struct bug)); p1->next=NULL; p1->x=290; p1->y=300; p1->last=p2; head_l=p1; } void move() { for(p1=head_f;p1!=NULL;p1=p1->next) { circle(p1->x,p1->y,2); } } void move_head() { } void move_body() { for(p1=head_l,p2=p1->last;p2!=NULL;p1=p2,p2=p2->last) { p1->x=p2->x; p1->y=p2->y; } } void ahead() { p1=head_f; p2=p1->next; p2=p2->next; if(p1->x==p2->x) { if(p1->y>p2->y) head_f->y+=5; else head_f->y-=5; } else { if(p1->x>p2->x) { head_f->x+=5; } else head_f->x-=5; } } void upon() { p1=head_f->next; p1=p1->next; head_f->y-=5; if(p1->x==head_f->x&&p1->y==head_f->y) { head_f->y+=5; ahead(); } } void down() { p1=head_f->next; p1=p1->next; head_f->y+=5; if(p1->x==head_f->x&&p1->y==head_f->y) { head_f->y-=5; ahead(); } } void left() { p1=head_f->next; p1=p1->next; head_f->x-=5; if(p1->x==head_f->x&&p1->y==head_f->y) { head_f->x+=5; ahead(); } } void right() { p1=head_f->next; p1=p1->next; head_f->x+=5; if(p1->x==head_f->x&&p1->y==head_f->y) { head_f->x-=5; ahead(); } } void food_f() { if(!food.judge) { food.x=(rand()%117+1)*5; food.y=(rand()%117+1)*5; food.judge=1; if(food.x<30||food.y<30||food.x>570||food.y>570) { setcolor(RED); circle(f

3. 如何利用C語言,C++語言打開USB串口,然後對其發送信號 跪求回答! 可行比加分!!

openfile和createfile,就可以,可以打開串口號的,創建接收信息,發送。。。

4. linux c語言編程

那麼牛的程序,不像是學校的考試題。
起碼是linux 下的C語言編程,搞嵌入式開發的吧。
我也來試試,正想向這個方向研究呢。呵呵

另:公司只能上網路,只能這里給你了.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#define LEN 100
main()
{
int fd, len;
int i;
char ch[LEN];
fd=open("test.txt",O_CREAT|O_RDWR,10705);
if(fd)
{
for(i=1;i<101;i++)
{
sprintf(ch,"%d",i);
write(fd,ch,strlen(ch));
}
close(fd);
}
fd = open("test.txt",O_RDWR);
lseek(fd,50,SEEK_SET);
if(fd)
{
len = read(fd,ch,1);
ch[len] = '\0';
printf("%s\n",ch);
}
lseek(fd,100,SEEK_SET);
if(fd)
{
len = read(fd,ch,1);
ch[len] = '\0';
printf("%s\n",ch);
}
close(fd);
if(!remove("test.txt"))
printf("test.txt have remove\n");
else
printf("can't remove\n");
}

這是第一題.

熱點內容
如何用電腦模擬安卓手機軟體 發布:2025-07-26 19:59:34 瀏覽:433
文件夾軟 發布:2025-07-26 19:59:33 瀏覽:771
資料庫清單 發布:2025-07-26 19:55:53 瀏覽:213
第一個視頻怎麼加入伺服器 發布:2025-07-26 19:50:33 瀏覽:861
mysql存儲過程print 發布:2025-07-26 19:50:29 瀏覽:387
xp共享密碼是什麼 發布:2025-07-26 19:36:21 瀏覽:835
大型房產源碼 發布:2025-07-26 19:35:40 瀏覽:514
sqlserverstring 發布:2025-07-26 19:13:22 瀏覽:949
電腦FTP密碼 發布:2025-07-26 18:58:17 瀏覽:250
dhcp伺服器添加靜態地址會過期嗎 發布:2025-07-26 18:57:37 瀏覽:409