VS2010软件开发平台的VC++项目——读取TXT文件的数据

xiaoxiao2021-02-27  396

VS2010软件开发平台的VC++项目——读取TXT文件的数据

望断—编程程序如下:

int main() { int tmp1 = 0; int tmp2 = 0; int tmp3 = 0; int tmp4 = 0; FILE * fp = fopen("IP.txt","rt"); //读取文件数据 while( !feof (fp) ) { fscanf(fp, "%ld, %ld, %ld, %ld \n", &tmp1, &tmp2, &tmp3, &tmp4); } fclose(fp);         unsigned char ip1 = tmp1; unsigned char ip2 = tmp2; unsigned char ip3 = tmp3; unsigned char ip4 = tmp4; }

备注:tmp 可以改为数组 tmp[i],然后通过while里面添加 i++,既读取多行数据

此程序中TXT的文件内容:192, 168, 6, 65


转载请注明原文地址: https://www.6miu.com/read-3719.html

最新回复(0)