目前,我正着手在C实施一个 log木方案,并根据数人的建议,即决定用植被和扫描器来取代红can,但不要像以前那样回到原木档案的最后一条线,否则,方案只会产生一个空白线,然后离开,我对C(几周前开始自学),因此,我可能只是对一些 d错误视而不见,但如果有人能够帮助我这样做,我会非常感激!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _GNU_SOURCE
void main(int argc, char *argv[], char *envp[])
{
FILE *fd;
char *name;
name = getenv("MCEXEC_PLAYERNAME");
char *filename;
filename = malloc(sizeof "/home/minecraft/freedonia/playerdata/deathlog-.txt" - 1 + strlen(name) + 1);
if (!filename) exit(EXIT_FAILURE);
sprintf(filename,"/home/minecraft/freedonia/playerdata/deathlog-%s.txt",name);
char *buff;
buff = malloc(1024);
char *finbuff;
finbuff = malloc(1024);
if ((fd = fopen(filename, "r")) != NULL)
{
fseek(fd, 0, SEEK_SET);
while(!feof(fd))
{
memset(buff, 0x00, 1024);
memset(finbuff, 0x00, 1024);
// fscanf(fd, "%[^
]
", buff);
fgets(buff, 1024, fd);
sscanf(buff, "%[^
]
", finbuff);
}
printf("%s
", finbuff);
}
else
printf( "fail" );
}
而对于行之有效的版本来说,这完全只是部分评论,而只是部分评论,还有没有将fin列入方案。
while(!feof(fd))
{
memset(buff, 0x00, 1024);
fscanf(fd, "%[^
]
", buff);
}