用VS2012编译C程序

时间:2012-08-21 09:24:14

标签: c compilation visual-studio-2012

我的程序看起来像那样

/* 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, “\nProper Usage is: “ );
 fprintf(stderr, “\n\nprint_it filename.ext\n” );
 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] );

Type & Run 1
nting Your Listings 27
 fprintf( stdprn, “%4d:\t%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\n\n”, page, filename );
 }

使用Win 8 + VS 2012.要编译它,请打开Developer Command Prompt,然后键入

cl print_it.c

有这个屏幕(一堆错误和警告)

enter image description here

我错过了什么?

2 个答案:

答案 0 :(得分:4)

看起来你不小心复制粘贴了。首先将每个替换为"

然后删除它:

Type & Run 1
nting Your Listings 27

答案 1 :(得分:1)

作为@cnicutar mentioned,首先修复损坏的双引号并删除垃圾。

但是,由于Windows上没有stdprn流,因此您无法使用Visual C ++编译此程序

有关如何解决此问题的详细信息,请参阅How can I make the printer work in C in MS VC++ Express edition?