读取txt某一行数据,并格式化数据

#include <iostream>

#include <string>

#include <Windows.h>

#include <fstream>

#include <sstream>

#include <signal.h>

#include <io.h>

#include <vector>

#include <process.h>

#include <cstdio>

using namespace std;

char readbuf[256] = "";

char EthernetMAC[256] = "";

int main()

{

//------------读取MAC Address-----------------------

char a[100], b[100], c[100];

int i = 6;    //第6行

FILE *fp = fopen("F:\\info.txt", "r");

if (fp == NULL) {

cout << "info.txt doesn't exist" << endl;

system("pause");

return(-1);

}

else {

while (fgets(c, 100, fp)) {    //读入每行数据

i--;

if (i == 0) strcpy(a, c);    //读到第6行数据

}

//cout<<a<<endl;

fclose(fp);

cout << a << endl;

sscanf(a, "%*s %*s %*s %s", readbuf);

cout << readbuf << endl;

 

return 0;

}

 

posted @ 2021-06-24 08:11  江南王小帅  阅读(258)  评论(0)    收藏  举报