回复 17楼 吹水佬
下面是我自己写的一点代码,我想输出文件指针当前所在的位置,不过输出的pos一直是0。。。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
FILE* fp;
fp5 = fopen("output","r" );
//int* s;
int* a;
if ((a = (int*)calloc(100, sizeof(int))) == NULL) {
printf("\n Error: failed in Calloc filegname");
exit(69);
}
char* p;
if ((p = (char*)calloc(1024, sizeof(char))) == NULL) {
printf("\n Error: failed in Calloc filegname");
exit(69);
}
char buffer[1024];
//char* aaa = "hello";
char* aaa = "groupr...";
int pos;
while (fgets(buffer, 1024, fp5)) {
char* p = strstr( buffer,aaa);
if (p != NULL) {
fseek(fp5, 0, SEEK_CUR);
pos = ftell(fp5);
printf("%d", pos);
printf("%s", p);
break;
}
//printf("%s", p);
}
}
[此贴子已经被作者于2017-10-28 13:50编辑过]