so here is my code -- whenever i try to compile it says SYNTAX error

#include <stdio.h>

long FindMaximum(long* numbers, int count)
{
long max = numbers[0];
int i;
for(i = 0; i< count; i++)
{
if (numbers[i] > max)
{
max = numbers[i];
}
}
return max;
}
long FindMinimum(long* numbers, int count)
{
long min = numbers[0];
int i;
for(i = 0; i< count; i++)
{

if (numbers[i] < min)
{
min = numbers[i];
}
}
return min;
}

float FindAverage(long* numbers, int count)
{
long sum = 0;
int i;
for(i = 0; i< count; i++)
{
sum += numbers[i];
}
if (sum == 0)
return 0;
return sum/(float)count;
}
void ParseFile(char* fileName)
{

printf("This Program will print the list of numbers in the data, and it’s Max, Min and Avg Values.\n");
char line[80];
long number[100];
int i;
for(i = 0; i<100;i++)
{
number[i] = 0;
}
FILE* fr = fopen (fileName, "r");  /* open the file for reading */
int index = 0;
while(fgets(line, 80, fr) != NULL)
{
sscanf (line, "%ld", &number[index++]);
printf ("%ld\n", number[index-1]);
}
printf("The minimum is %ld \n",FindMinimum(number,index));
printf("The maximum is %ld \n",FindMaximum(number,index));
printf("The average is %4.2f \n",FindAverage(number,index));
fclose(fr);
}

int _tmain(int argc, _TCHAR* argv[])
{
ParseFile("c:\\justin\\data.txt");
return 0;
}

here is error:

Compiler: Default compiler
Executing  gcc.exe...
gcc.exe "C:\cygwin\home\Justin\Individual_Project.c" -o "C:\cygwin\home\Justin\Individual_Project.exe"    -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib"
C:\cygwin\home\Justin\Individual_Project.c:68: error: syntax error before "_TCHAR"

Execution terminated

Can someone tell me what exactly is off?

3
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by Nick Evan

My bet is that you copied some code from the net that was written with VC++ 2010 Express and you are trying to compile it with gcc???

_TCHAR is a macro defined in tchar.h. You can just replace it with char* so that the line looks like this: int main(int argc, char* argv[])

Edited by Ancient Dragon: n/a

Thnx - its fixed,

Hey man, you guessed right -- now that i fixed this -- i try to run it in Cygwin -- but it comes up _ Segmentaion Fault (Core Dumped)... any idea on what might be wrong here?

I am a total begineer , sir.

what operating system are you running? If *nix then use debugger named gdb and it will tell you where the error was by reading that core file.

Actually - i think it was because i didnot assign the file name of the data set. Now its working (yea i totally copied the code...) hopefully not nect time.. Thnx for your help Ancient Dragon.

If you would add somesort of check if the file you're trying to open actually exist, then you would probably not get this error.

*moved to C

Edited by Nick Evan: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.