compiling c program with visual studio

I am trying to compile a program written in C on visual studio c++ 2010. I created a new project and placed all the .c files and h files into a new project. As have read from other sources, I selected the option of 'not using precompiled headers' from the properties window of each .c file. I also selected 'compile as C code' from the advanced window on the properties window. When I compile I keep getting the following errors which seem to correspond to lines 11 and 12 of the code which is shown below:


Error 1 error C2143: syntax error : missing ';' before 'type'

and


Error 2 error C2065: 'i' : undeclared identifier

These errors

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "database.h"

void delete_database ( DATABASE * database_pt ){

  if ( database_pt->number_of_tracks == 0 )
  {
    free ( database_pt->tracks_pt );
    return ;
  }

  int i = 0;
  while ( i < database_pt->number_of_tracks )
  {
	  //printf("Deleting track %d ... \n", i );
	  delete_track (&(database_pt->tracks_pt[i]));
	  i ++;
  }

  free ( database_pt->tracks_pt );
  //printf("Deleting search structure ...\n");
  delete_search_structure ( database_pt->search_structure_pt );
}

void load_database ( DATABASE * database_pt, char * file_name )
{
	FILE * fp;
	int number_of_tracks;
	int err;
	int i;

	fp = fopen ( file_name, "r" ) ;
	if ( fp == NULL ) 
	{
		printf("Error: can't open file %s!\n", file_name );
		exit(1);
	}

  err = fscanf ( fp, "%d", &number_of_tracks);
  if ( err != 1 ){
    printf("Error: fscanf!\n");
    exit(1);
  }
.
.
.
.


Any ideas how to resolve these errors??????????????
1
2
3
4
5
6
7
  int i = 0;
  while ( i < database_pt->number_of_tracks )
  {
	  //printf("Deleting track %d ... \n", i );
	  delete_track (&(database_pt->tracks_pt[i]));
	  i ++;
  }


The last line here, with the incrementation, is probably the source of one or both errors. You have a space between the 'i' and the "++".
Last edited on
Just tried changing that and I still get the same error...
MS VC++ 2010 does support the C99 Standard. This means that all variables you should declare in the very beginning of a block. So, for example, your definition of variable i in the middle of the function body

int i = 0;

is incorrect.
Topic archived. No new replies allowed.