Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

windows - C compilation errors on using stdprn

My OS is: Windows 8

IDE: VS 2012

Here is my C program. (from book)

/* print_it.c—This program prints a listing with line numbers! */
#include <stdlib.h>
#include <stdio.h>

void do_heading(char *filename);

int line = 0, page = 0;

int main( int argv, char *argc[] )
{
  char buffer[256];
  FILE *fp;

  if( argv < 2 ) 
  {
    fprintf(stderr, "
Proper Usage is: " );
    fprintf(stderr, "

print_it filename.ext
" );
    return(1);
  }

  if (( fp = fopen( argc[1], "r" )) == NULL )
  {
    fprintf( stderr, "Error opening file, %s!", argc[1]);
    return(1);
  }

  page = 0;
  line = 1;
  do_heading( argc[1]);

  while( fgets( buffer, 256, fp ) != NULL )
  {
    if( line % 55 == 0 ) 
      do_heading( argc[1] );
    fprintf( stdprn, "%4d:	%s", line++, buffer );
  }

  fprintf( stdprn, "f" );
  fclose(fp);
  return 0;
}

void do_heading( char *filename )
{
  page++;

  if ( page > 1)
    fprintf( stdprn, "f" );

  fprintf( stdprn, "Page: %d, %s

", page, filename );
}

Trying to compile. Opened Developer Command Prompt, and typed

cl print_it.c

Got this screen (bunch of errors and warnings)

http://content.screencast.com/users/TT13/folders/Jing/media/ff48bfe2-7e83-4d93-b1c5-db7ab7e553b8/2012-08-21_1458.png

What am I missing?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

stdprn isn't part of standard C. stdprn is a stream DOS compilers provided. Should probably be avoided.

You could try turning off ANSI compatibility to get stdprn to work. (Reference)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...