собственно вот:
- Код: Выделить всё
function textfileread(var fn: pchar): pchar;
var fs: file; count: integer; content: pchar;
begin
count:=0;
if fn <> NIL then
begin
Assign(fs,fn);
if @fs <> NIL then
begin
seek(fs, FileSize(fs));
count:= FilePos(fs);
reset(fs);
if count>0 then
begin
GetMem(content, sizeof(char)*(count+1));
count:=Blockread(fs, content, count, sizeof(char));
content[count]:=#10;
end;
close(fs);
end;
end;
textfileread:=content;
end;
Ошибка следующая:
http://clip2net.com/s/2LK8K
Может кроме этого еще что-то в коде неправильно?
Или есть какие-то уже готовые аналоги?
Списывал с этого кода.
- Код: Выделить всё
char *textFileRead(char *fn) {
FILE *fp;
char *content = NULL;
int count=0;
if (fn != NULL) {
fp = fopen(fn,"rt");
if (fp != NULL) {
fseek(fp, 0, SEEK_END);
count = ftell(fp);
rewind(fp);
if (count > 0) {
content = (char *)malloc(sizeof(char) * (count+1));
count = fread(content,sizeof(char),count,fp);
content[count] = '\0';
}
fclose(fp);
}
}
return content;
}