Only One simple error in code. not able to solve it.

Error regarding code directory , please help

Page 1 of 1

11 Replies - 4984 Views - Last Post: 31 March 2008 - 09:22 AM Rate Topic: -----

#1 Tavisha  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 28-February 08

Only One simple error in code. not able to solve it.

Post icon  Posted 30 March 2008 - 08:39 PM

HI all

Like I have mentioned before I am trying to work on Image processin code..
I wrote this error out code, it deals with encoding and RCPC channel code
Anyway.. I am getting this error when I execute it. This is the only error I am gettin and not able to solve it

please help.....
Tavisha

[ code]

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

void err (float eprob)

{
FILE *f1, *f2;
int r,num=0;
float x;
float r_num;
char a,b='0', c ='1';
f1= fopen("rcpcputput.txt","r");
f2=fopen( "erroutput.txt","w");

printf("\n Enter the error probability");
scanf("%1f",&eprob);
printf("\n Error probability is %1f",eprob);

while (!feof(f1))
{
fscanf(f1,"%c",&a);
printf("\n read is %c",a);
r=(10000);
printf("random is %d",r);
x=(float)r;

r_num=x/10000;
if (r_num<eprob)
{
if (a==B)
a=c;
else a=b;
num++;
}
fprintf (f2,"%c",a);
printf("random is %f probabilty is %f written is %c",r_num,eprob,a);

}
printf("\n\n Number of bit errors is %d",num);
fclose(f1);
fclose(f2);
getch;
}

[code ends]

C:\TurboCPP\C code\MyErr.c||In function `void err(float)':|
C:\TurboCPP\C code\MyErr.c|43|warning: statement is a reference, not call, to function `getch'|
C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\libmingw32.a(main.o):main.c:(.text+0x104)|| \undefined reference to `_WinMain@16'|
||=== Build finished: 1 errors, 1 warnings ===|



I even tried to get the MINGW \bin\..lib file in my c:\ turbocpp\C code file but no help there!!!


Looking forward to replies...

Thanks....
The error I get is :

Is This A Good Question/Topic? 0
  • +

Replies To: Only One simple error in code. not able to solve it.

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5363
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Only One simple error in code. not able to solve it.

Posted 30 March 2008 - 08:53 PM

I don't see your main code block anywhere? Every c/c++ program must have main.

Also :
:code:
Was This Post Helpful? 0
  • +
  • -

#3 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,120
  • Joined: 22-February 08

Re: Only One simple error in code. not able to solve it.

Posted 30 March 2008 - 08:54 PM

Please :code: the next time u post. :)

I'm not sure about this as I dont have my compiler right now, but I think in any code, there should be one 'main' function, which I dont see in ur code. try rename ur function to 'main'. correct me if I'm wrong anyway :P
Was This Post Helpful? 0
  • +
  • -

#4 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Only One simple error in code. not able to solve it.

Posted 30 March 2008 - 09:24 PM

\undefined reference to `_WinMain@16'|

That's the problem... It is just because you haven't got a main function in your code. Try fixing that.

The other thing is:
C:\TurboCPP\C code\MyErr.c|43|warning: statement is a reference, not call, to function `getch'|
That's at the end of your code, it should be getch(); - you missed the brackets :)

This post has been edited by gabehabe: 30 March 2008 - 09:26 PM

Was This Post Helpful? 0
  • +
  • -

#5 Tavisha  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 28-February 08

Re: Only One simple error in code. not able to solve it.

Posted 31 March 2008 - 06:26 AM

HI There


thanks for the replies.

I put int main() before the code but it gives me this error now...


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

int main()
void err (float eprob)

{
   FILE *f1, *f2;
   int r,num=0;
   float x;
   float r_num;
   char a,b='0', c ='1';
   f1= fopen("rcpcputput.txt","r");
   f2=fopen( "erroutput.txt","w");

	printf("\n Enter the error probability");
	scanf("%1f",&eprob);
	printf("\n Error probability is %1f",eprob);

	while (!feof(f1))
	{
		fscanf(f1,"%c",&a);
		printf("\n read is %c",a);
		r=(10000);
		printf("random is %d",r);
		x=(float)r;

		r_num=x/10000;
		if (r_num<eprob)
		 {
			 if (a==b)
			 a=c;
			 else a=b;
			 num++;
		 }
		fprintf (f2,"%c",a);
		printf("random is %f probabilty is %f written is %c",r_num,eprob,a);

	}
   printf("\n\n Number of bit errors is %d",num);
   fclose(f1);
   fclose(f2);
   getch();
}





Error is : C:\TurboCPP\C code\MyErr.c|6|error: expected initializer before "void"|
||=== Build finished: 1 errors, 0 warnings ===|



What should I do nw?
Was This Post Helpful? 0
  • +
  • -

#6 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1382
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Only One simple error in code. not able to solve it.

Posted 31 March 2008 - 06:41 AM

You can't declare or define a function in your main()
Try rearranging your code like so:
//declare the function
void err(float eprob);

int main()
{
    . . .
    //call the function
    err(float eprob);
    . . .
}

//define the function
void err(float eprob)
{
    . . .
}



Hope this helps :)
Was This Post Helpful? 0
  • +
  • -

#7 Tavisha  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 28-February 08

Re: Only One simple error in code. not able to solve it.

Posted 31 March 2008 - 06:53 AM

Now I get this error !!!!

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


void err (float eprob);

int main()

 {

   FILE *f1, *f2;
   int r,num=0;
   float x;
   float r_num;
   char a,b='0', c ='1';
   f1= fopen("rcpcputput.txt","r");
   f2=fopen( "erroutput.txt","w");


	   err(float eprob);

	printf("\n Enter the error probability");
	scanf("%1f",&eprob);
	printf("\n Error probability is %1f",eprob);


	while (!feof(f1))

	{
		fscanf(f1,"%c",&a);
		printf("\n read is %c",a);
		r=(10000);
		printf("random is %d",r);
		x=(float)r;

		r_num=x/10000;
		if (r_num<eprob)
		 {
			 if (a==b)
			 a=c;
			 else a=b;
			 num++;
		 }
		fprintf (f2,"%c",a);
		printf("random is %f probabilty is %f written is %c",r_num,eprob,a);

	}
   printf("\n\n Number of bit errors is %d",num);
   fclose(f1);
   fclose(f2);
   getch();
}




Error:
C:\TurboCPP\C code\MyErr.c||In function `int main()':|
C:\TurboCPP\C code\MyErr.c|21|error: expected primary-expression before "float"|
C:\TurboCPP\C code\MyErr.c|24|error: `eprob' was not declared in this scope|
||=== Build finished: 2 errors, 0 warnings ===|



Hellpppppp
Was This Post Helpful? 0
  • +
  • -

#8 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,120
  • Joined: 22-February 08

Re: Only One simple error in code. not able to solve it.

Posted 31 March 2008 - 07:10 AM

because there's only function prototype that u declared there.

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


void err (float eprob);	 /*this is function prototype*/

int main()

{
........
}


where's ur 'err' function? I dont see it anywhere in ur code.

int main()

{
........
}

void err(float eprob)	  /*after main function, there should be a 'err' function here*/
{
......					 /*and the function should be doing something*/
}


hope this helps! :)

This post has been edited by red_4900: 31 March 2008 - 07:11 AM

Was This Post Helpful? 0
  • +
  • -

#9 Tavisha  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 28-February 08

Re: Only One simple error in code. not able to solve it.

Posted 31 March 2008 - 07:23 AM

what does this mean?



C:\TurboCPP\c_work\ERR.C|6|error: expected initializer before "void"|
||=== Build finished: 1 errors, 0 warnings ===|


????
Thats the only error Iget when I jus put int main () in the begining of the code.


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

int main()
   void  err(float e_prob)
{
	FILE *f1, *f2;
	int r,num=0;
	 float x;
	float r_num;
	char a,b='0',c='1';
	f1=fopen("ENCODED.txt","r");
	f2=fopen("errout.txt","w");

	printf("\nEnter error probability");
	scanf("%lf",&e_prob);
	printf("\nError prob is %lf",e_prob);

	while(!feof(f1))
	{
		fscanf(f1,"%c",&a);
		printf("\nread is %c ",a);
		r=(10000);
		printf("random is %d ",r);
		x=( float)r;
		r_num=x/10000;
		if (r_num<e_prob)
		{
			if (a==b)
			a=c;
			else
			a=b;
			num++;
		}
		fprintf(f2,"%c",a);
		printf("rnd is %f prob is %f written is %c",r_num,e_prob,a);
  //		delay(10);
	}
	printf("\n\nNumber of bit errors is %d",num);
	fclose(f1);
	fclose(f2);
//	getch();
}




Error:C:\TurboCPP\c_work\ERR.C|6|error: expected initializer before "void"|
||=== Build finished: 1 errors, 0 warnings ===|
Was This Post Helpful? 0
  • +
  • -

#10 Tavisha  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 28-February 08

Re: Only One simple error in code. not able to solve it.

Posted 31 March 2008 - 08:02 AM

some one pleasssee give me any directions !!

waiting for ur replies.....
Was This Post Helpful? 0
  • +
  • -

#11 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,120
  • Joined: 22-February 08

Re: Only One simple error in code. not able to solve it.

Posted 31 March 2008 - 09:09 AM

where did u get the code? or u done it urself? because u declared the function 'err' but u never define it anywhere in ur code. and it has been mentioned before that function prototype should be declared before 'main' function not in the 'main' function.
Was This Post Helpful? 0
  • +
  • -

#12 Tavisha  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 28-February 08

Re: Only One simple error in code. not able to solve it.

Posted 31 March 2008 - 09:22 AM

hey there

thanks for ur replies..

I got it working nwo.. I was mixing the two things.

anyhow, this is a code I am trying to learn. it is someone elses.

Thanks once again...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1