I am a newbie in programming and I'm using visual studio.
i typed in this

#include <stdio.h>
#include <conio.h>
#define PI 3.1416 

void main(void)
{                               

float radius, circumference, area;

radius = 2.5;

circumference = 2 * PI * radius;

area = PI * radius * radius;

printf("radius of a circle = %f cm\n", radius);
printf("circumference = %f cm\n", circumference); 
   printf("Area = %f sq cm\n", area);  
   getch();
} 

it gives me

1>------ Build started: Project: tryagn, Configuration: Debug Win32 ------
1>Build started 21/04/2012 5:31:18 PM.
1>InitializeBuildStatus:
1>  Touching "Debug\tryagn.unsuccessfulbuild".
1>ClCompile:
1>  tryagain.c
1>d:\vc\chap2\sln\tryagn\tryagain.c(4): error C2449: found '{' at file scope (missing function header?)
1>d:\vc\chap2\sln\tryagn\tryagain.c(14): error C2059: syntax error : '}'
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.29
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

What is wrong with it?

Ezzaral commented: You're a newb in comminc -3

Recommended Answers

All 4 Replies

I'm not sure if visual studio supports a deprecated library like conio.h and it's functions like getch(), try removing them

also use int main instead of void main

do the following changes :

void main(void) to int main()

remove getch(), use header file "stdlib.h" and use system("pause") at place of getch()
It will hold the screen for you. (same as getch();)

use return 0 for returning nothing(same as void) in the end of the program.
return 0; is necessary because you are using an integer return type main function.

sorry for bad format reply...but i hope it will help :)

This syntax error below tells me that you have only an open brace somewhere in your code. That is, there is no corresponding closing brace. But yet I do not see this error condition in your posted code. Are you sure you posted the faulty code?

> d:\vc\chap2\sln\tryagn\tryagain.c(4): error C2449: found '{' at file scope (missing function header?)
> 

I can only assume this second syntax error is related to the missing closing bracket.

> > d:\vc\chap2\sln\tryagn\tryagain.c(14): error C2059: syntax error : '}'
> 
> 
> 

How about posting the faulty tryagain.c code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.