#include<io.h>
int main(int argc, char *argv[])
{
struct _finddata_t fa
long fHandle
if( (fHandle=_findfirst( "*.txt", &fa ))==-1L )//这老派里可以改成需要的目录
{
printf( "当前目录下没有txt文件裤厅\n")
return 0
}
else
do
{
printf( "胡含隐找到文件:%s\n", fa.name )
}while( _findnext(fHandle,&fa)==0 )
_findclose( fHandle )
return 0
}
//data.txt文件内容汪谨如下\x0d\x0a\x0d\x0a1个猪\x0d\x0a2个猪旁陵丛\x0d\x0a3个猪\x0d\x0a4个猪\x0d\x0a5个猪\x0d\x0a6个猪\x0d\x0a7个猪\x0d\x0a8个猪\x0d\x0a\x0d\x0a//运行结果一\x0d\x0athe 8 line :8 个 猪\x0d\x0a\x0d\x0aPress any key to continue \x0d\x0a//运行结果运樱二\x0d\x0aout of range!\x0d\x0aPress any key to continue \x0d\x0a\x0d\x0a//代码如下\x0d\x0a#include \x0d\x0a#include \x0d\x0a#include \x0d\x0amain(void)\x0d\x0a{\x0d\x0aint lid,cnt=0,flag=0\x0d\x0achar buf[100]="\0"\x0d\x0aFILE *fp\x0d\x0a\x0d\x0asrand((unsigned)time(NULL))\x0d\x0afp=fopen("data.txt","r")\x0d\x0alid= rand()%10+1\x0d\x0awhile (fgets(buf,99,fp)!=NULL)\x0d\x0a{\x0d\x0aif(cnt==lid)\x0d\x0a{\x0d\x0aprintf("the %d line :%s\n",lid+1,buf)\x0d\x0aflag=1\x0d\x0abreak\x0d\x0a}\x0d\x0acnt++\x0d\x0a}\x0d\x0aif (flag==0)\x0d\x0a{\x0d\x0aprintf("out of range!\n")\x0d\x0a}\x0d\x0a}欢迎分享,转载请注明来源:内存溢出
评论列表(0条)