Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,345 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,118 people online right now. Registration is fast and FREE... Join Now!




Expected Intializer problem

 
Reply to this topicStart new topic

Expected Intializer problem, I get only error regarding intializer, please solve it !

Tavisha
post 1 Apr, 2008 - 09:17 PM
Post #1


New D.I.C Head

*
Joined: 28 Feb, 2008
Posts: 42

Hi All,

I run my code and all is well but I keep getting this one error.Please help me in solving it.

[code]

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

int main()

void err(float e_prob)
{
FILE *f1, *f2;
int r,num=0;
long float x;
long float r_num;
char a,b='0',c='1';
f1=fopen("ENCODED.txt","r");
f2=fopen("errout.txt","w");
clrscr();
// printf("\nEnter error probability");
// scanf("%lf",&e_prob);
printf("\nError prob is %lf",e_prob);
..
....
......

.......

[\code]

The Error I get is :
C:\TurboCPP\c_work\c_work\c_work\c_work\ERR.C|7|error: expected initializer before "void"|
||=== Build finished: 1 errors, 0 warnings ===|

Also I get the same error in diff prog, which says:
C:\TurboCPP\c_work\c_work\c_work\c_work\ERR.C|7|error: expected initializer before "int"|
||=== Build finished: 1 errors, 0 warnings ===|


How should I solve it ?

what exactly is an intialzer?

Thanks !!!
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 1 Apr, 2008 - 09:27 PM
Post #2


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,328



Thanked 57 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


try changing int main() to this:

cpp

int main(void) {
FILE *f1, *f2;
int r,num=0;
long float x;
long float r_num;
char a,b='0',c='1';
f1=fopen("ENCODED.txt","r");
f2=fopen("errout.txt","w");
clrscr();
// printf("\nEnter error probability");
// scanf("%lf",&e_prob);
printf("\nError prob is %lf",e_prob);
}


However, this isn't a simply fix. You have not provided enough information about this code.

The last line printf("\nError prob is %lf",e_prob); is going to require the variable e_prob, which in your code is passed into the function err. What exactly is the purpose of this code, & where did you get it?
User is offlineProfile CardPM

Go to the top of the page

Tavisha
post 2 Apr, 2008 - 09:54 AM
Post #3


New D.I.C Head

*
Joined: 28 Feb, 2008
Posts: 42

hey I tried doing that but it didnt help it still says expected intialiser before err now !

it is basically a channel coding code which uses rcpc punctured codes .. it is a code my proff has told me to run and manipulate to get my own results so first ia m trying to learn it.... ohmy.gif(

i still cant figure out what is an intializer in C ? what does it mean ?
User is offlineProfile CardPM

Go to the top of the page

gabehabe
post 2 Apr, 2008 - 10:33 AM
Post #4


Working Girl.

Group Icon
Joined: 6 Feb, 2008
Posts: 5,402



Thanked 94 times

Dream Kudos: 2625

Expert In: Dingleberries

My Contributions


You're declaring void err(float e_prob) inside your main code. Move it outside of the main - you can't declare a function within main()

There are two ways of creating a function:
cpp

void err(float e_prob); //Declaration

int main()
{
. . .
}

void err(float e_prob) //Definition
{
. . .
}


Or, you can do it without a declaration. (I prefer to declare it and define it later - this way, you can easily look at a list of all your functions without having to scroll through loads of code just to find all your functions smile.gif

The other way (without the declaration) is as follows:
cpp

void err(float e_prob) //Immediate definition
{
. . .
}

int main()
{
. . .
}


As for your second problem, I ***THINK*** that once you've solved this problem, the other one should fix itself smile.gif

Hope this helps
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 03:40AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month