• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

Problem on compiling *.c source file when using fpt = fopen() on VC++.

I am having a problem on compiling C source file in Visual C++ 6.0 when using FILE *. Suppose I have the following source file:

// test.c

#include <stdio.h>
     FILE *fpt;
     fpt = fopen("source.c", "r");
     int i;

Whenever I use FILE *fpt and fopen it, I will get errors, such as:

error C2143: syntax error : missing ';' before 'type' (refer to the line of "int i")

If I change the source file's extension to "cpp" and recompile it, the problem solved. How can I keep the "c" extension and let the FILE * works in VC++?

Thanks and hope to hear from you ASAP.
1 Solution
switch between int i ; and fopen;
like this:

FILE *fpt;
int i;
fpt = fopen("source.c", "r");

In ANSI C You can not define parameters in the middle of the code.


Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now