查找 '\n' or '\r',并计数,
然后读取你需要的数据。

解决方案 »

  1.   

    把整个文件读到内存里面,然后
    strchr('\');n次
      

  2.   


    把整个文件读到buf里面,然后
    strchr(buf,'\r');n次  
      

  3.   

    把整个文件读到buf里面,然后
    strchr(buf,'\r');n-1次
    fgets(anotherbuf);  
      

  4.   


    \\我得到emailBuf后,该怎么做,请指点,谢谢!
     char * emailBuf;
     FILE *stream;
     struct _stat buf;
     int result,filesize,numread;

    //获得文件大小---begin
       result = _stat("d:\\emaillist.txt", &buf );
       if( result == 0 )
        {
         filesize=buf.st_size;
       }
    //获得文件大小---end
    //读取文件----begin
       if( (stream = fopen("d:\\emaillist.txt", "r+t" )) != NULL )
       {
      emailBuf=new char[filesize+1];
          numread=fread(emailBuf,1, filesize, stream );
      emailBuf[numread]='\0';
      fclose( stream );
       }//get file end//下面的算法怎么写? 
      

  5.   

    偶试一下:
    假使偶要读第n行的内容!char szText[256];memset (szText, 0, sizeof(szText));int nStartIndex = 0;
    int nIndex = 0;int nLine = 0;while(nIndex <= numread)
    {
    if (emailBuf[nIndex++] == '\n')
    {
    nLine ++;
    if (nLine == n-1) nStartIndex = nIndex;
    if (nLine == n) 
    {
    strncpy (szText, emailBuf + nStartIndex, nIndex - nStartIndex-1-1);
    break;
    }
    }
    }
      

  6.   

    谢谢大家;
    to whitewaterbluesky:
    strncpy (szText, emailBuf + nStartIndex, nIndex - nStartIndex-1-1);
    应该为
    strncpy (szText, emailBuf + nStartIndex, nIndex - nStartIndex-1);