在下急着需要分行读写文本文件内容的例子,是在标准C下,同时也需要进行块读写的,也是在标准C下的!谢谢!

解决方案 »

  1.   

    #include <stdio.h>int main( void )
    {
       FILE *stream;
       char line[100];   if( (stream = fopen( "crt_fgets.txt", "r" )) != NULL )
       {
          if( fgets( line, 100, stream ) == NULL)
             printf( "fgets error\n" );
          else
             printf( "%s", line);
          fclose( stream );
       }
    }
      

  2.   

    #include <stdio.h>void main( void )
    {
       FILE *stream;
       char list[30];
       int  i, numread, numwritten;   /* Open file in text mode: */
       if( (stream = fopen( "fread.out", "w+t" )) != NULL )
       {
          for ( i = 0; i < 25; i++ )
             list[i] = (char)('z' - i);
          /* Write 25 characters to stream */
          numwritten = fwrite( list, sizeof( char ), 25, stream );
          printf( "Wrote %d items\n", numwritten );
          fclose( stream );   }
       else
          printf( "Problem opening the file\n" );   if( (stream = fopen( "fread.out", "r+t" )) != NULL )
       {
          /* Attempt to read in 25 characters */
          numread = fread( list, sizeof( char ), 25, stream );
          printf( "Number of items read = %d\n", numread );
          printf( "Contents of buffer = %.25s\n", list );
          fclose( stream );
       }
       else
          printf( "File could not be opened\n" );
    }
      

  3.   

    aspnetwuxueyou(ActiveSync)
        不好意思,是在那里实现行读写呢?
      

  4.   

    fgets读一行。
    fwrite的时候加上回车、换行就是写一行了