69,371
社区成员
发帖
与我相关
我的任务
分享
FILE *fp,*fp1;
int l,i,j;
char ip[20];
char temp[100];
char ch='\0';
/*以下是获取本机IP*/
system("ipconfig >d:\\myip.txt");
if((fp1=fopen("d:\\myip.txt","r"))==NULL)
{
printf("the file can not open:\nPress any key to exit:");
getch();
exit(1);
}
for (i=0;i<7;i++)
{
fgets(temp,80,fp1); /*跳过一些行*/
}
fgets(temp,80,fp1);
i=0;j=0;
while (temp[i++]!=':')
;
while (temp[i]!='\n')
ip[j++]=temp[i++];
ip[j]=0;
//printf("IP=%s\n",ip);
fclose(fp1);
system("del d:\\myip.txt");
rename("d:\\neicun.txt",ip);
//getch();