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

Posted on 2003-03-09
Medium Priority
Last Modified: 2010-04-01
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.
Question by:cwchan80
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment

Accepted Solution

peter_sheynkman earned 80 total points
ID: 8097847
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question