966 static void readLineNumVal(unsigned char u8lineNum)
967 {
968 char c;
969 FILE *fp = NULL;
970 unsigned int lineNum = 0;
971 unsigned char i = 0, j = 0;
972 char readNumVal[32] = {0};//存放要读取行的内容,由于本次操作需要读取的每一行都是32字节
973
974 fp = fopen(FILE_PATH, "r+");
975 while((c = getc(fp)) != EOF)
976 {
977 if('\n' == c)
978 {
979 lineNum++;
980 if(lineNum > (u8lineNum + 3))//笔者是从文件的第三行开始读的,如果要从第一行开始的话,直接将3改为0即可
981 {
982 goto stopReadfile;
983 }
984 continue;
985 }
986 if(lineNum == (u8lineNum + 3))
987 {
988 readNumVal[i++] = c;
989 printf("%02c", c);
990 }
991 }
992 stopReadfile:
993 fclose(fp);
994 fp = NULL;
995
996 LOGINFO("\nnow is ready. lineNum = %d, i= %d\n", lineNum, i);
997
1008
1009 }
C语言实现读取文件中指定行号的内容
猜你喜欢
转载自blog.csdn.net/u010299133/article/details/82927367
今日推荐
周排行