fsad6546
F5343
646546345asfdsa
fsadfsda
456749+8
ASDFSAD
ÏÖÒª¶ÁÈ¡µÚÒ»ÐÐ
windowϵÚÒ»ÐнáÊøÊÇ\r\n,8¸ö×Ö·ûÖ®ºóÊÇ¡®\r\n¡¯,cÓïÑÔfgetc¶Áȡʱ£¬µÚ¾Å¸öºÍµÚÊ®¸ö×Ö·û¾ùΪ'\n',ͬʱÏÂÒ»ÐеÄFÊǵÚ11¸ö×Ö·û
linuxÏÂûÓлسµ'\r',Óл»ÐУ¬¶ÁÍê8¸ö×Ö·ûºóÊÇ'\n',ͬʱÏÂÒ»ÐеÄFÊǵÚÊ®¸ö×Ö·û
ÒÔϳÌÐòÊǶÁÈ¡Îı¾Îļþ£¬È»ºóÊä³ö
£¨×¢ÒâÒªÏȵõ½Ò»Ðеij¤¶È£©
ÒýÓÃ:#include
#include
#include
int main()
{
char *str,c;
str=(char*)malloc(1);
int k=0,sum=0;
FILE * pfile= fopen("test.txt","r");
while(1)
{
int i=0;
char d;
int k=ftell(pfile);
fseek(pfile,8,SEEK_SET);
c=fgetc(pfile);
while( c!='\n')
{
if(c==-1)
{
fseek(pfile,-i,SEEK_CUR);
goto first;
}
i++;
c=fgetc(pfile);
k=ftell(pfile);
}
k=ftell(pfile);
d=fgetc(pfile);
k=ftell(pfile);
fseek(pfile,-i-2,SEEK_CUR);//linuxÏÂÕâÒª¸ÄΪ fseek(pfile,-i-1,SEEK_CUR);
first:
free(str);
str=(char*)malloc(i+2);
if(fgets(str,i+2,pfile)==NULL)
{
break;
}
printf(str);
}
fclose(pfile);
return 0;
}
»Æ¸»Ç¿ ÓÚ 2008-06-14 10:41:44·¢±í:
Tofrodos
http://www.thefreecountry.com/tofrodos/index.shtml
shuke ÓÚ 2008-06-14 10:26:46·¢±í:
dos ºÍ unixϵÄÎı¾¸ñʽ²»Í¬. unixÏÂÓÐunix2dosÕâ¸öÃüÁîÄÜת»»