9 Replies - 902 Views - Last Post: 09 October 2012 - 01:20 PM Rate Topic: -----

#1 BeRG  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-October 12

12 errors

Posted 07 October 2012 - 01:26 PM

#include <stdio.h>
#include <math.h>


float menor(float lista[], int n);
float maior(float lista[],int n);


void main()
{
	int i,g;
	int b1,b2,b3,b4,b5,b6,b7,b8,b9;
	int frab[10]={0};
	float frel[10]={0};
	float inf, sup, p;
	int nlinhas;

	FILE *pfile;  // Apontador para uma estrutura de um ficheiro
	char nome_ficheiro[]= {"C:\\Users\\Vladimir\\Desktop\\Ficha1\\DOC\\Teste.txt"};  // String com o nome do ficheiro
	float * valores;// Apontador para o Array dinamico que guarda os valores lidos do ficheiro

	pfile= fopen(nome_ficheiro, "r");

	if(pfile == NULL)
		printf("ERRO NA ABERTURA DO FICHEIRO");
	else
	{
		fscanf(pfile, "%d", &nlinhas);
		valores = new float [valores];

		p=(maior(valores, nlinhas) - menor(valores, nlinhas))/10;
		printf("%d\n",p);
		b1=menor + p;
		b2=b1 + p;
		b3=b2 + p;
		b4=b3 + p;
		b5=b4 + p;
		b6=b5 + p;
		b7=b6 + p;
		b8=b7 + p;
		b9=b8 + p;

		for (i=0; i<nlinhas; i++)
		{
			fscanf(pfile, "%f", &valores[i]);
			printf ("%2d %4.2f\n", i, valores[i]);


			if (valores[i]>=menor && valores[i]<b1) ++frab[0];
		    else if(valores[i]>=b1 && valores[i]<b2) ++frab[1];
		    else if(valores[i]>=b2 && valores[i]<b3) ++frab[2];
		    else if(valores[i]>=b3 && valores[i]<b4) ++frab[3];
		    else if(valores[i]>=b4 && valores[i]<b5) ++frab[4];
		    else if(valores[i]>=b5 && valores[i]<b6) ++frab[5];
		    else if(valores[i]>=b6 && valores[i]<b7) ++frab[6];
		    else if(valores[i]>=b7 && valores[i]<b8) ++frab[7];
		    else if(valores[i]>=b8 && valores[i]<b9) ++frab[8];
		    else if(valores[i]>=b9 && valores[i]<=maior) ++frab[9];
		}


	}

		int i=0;
		float inf=menor;
		float sup=p;


	printf("\n Limites \t Frequencia Absoluta \t Frequencia Relativa \t Grafico \n\n");

	do 	{ 

		frel[i]= float (frab[i])/nlinhas*100.00;

		printf(" %5.2f a %.2f\t            %d\t                    %1.2f %%\t      ",inf,sup,fabs[i],frel[i]);

		for(g=1;g<=frab[i];++g)
		{				
			printf("*");
		}

		printf("\n");
		inf+=p;
		sup+=p;
		i++;

	}
	while(i<10);

	delete[] valores;
}

float menor(float lista[], int n);
{
	float min=lista[0];
	int i;
	for(i=1; i<n; i++)
	{
		if(lista[i]<min)
		{
			min=lista[i];
		}
	}
	return min;
}
float maior(float lista[],int n)
{
	float max=lista[0];
	int i;
	for(i=1; i<n; i++)
	{
		if(lista[i]>max)
		{
			max=lista[i];
		}
	}
	return max;
}

This post has been edited by jimblumberg: 07 October 2012 - 01:33 PM
Reason for edit:: Added missing Code Tags, Please learn to use them.


Is This A Good Question/Topic? 0
  • +

Replies To: 12 errors

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4074
  • View blog
  • Posts: 12,571
  • Joined: 25-December 09

Re: 12 errors

Posted 07 October 2012 - 01:34 PM

Do you have a problem or question?

If you are getting error messages, post the complete error messages exactly as they appear in your development environment.


Jim

This post has been edited by jimblumberg: 07 October 2012 - 01:34 PM

Was This Post Helpful? 0
  • +
  • -

#3 BeRG  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-October 12

Re: 12 errors

Posted 07 October 2012 - 01:51 PM

View Postjimblumberg, on 07 October 2012 - 01:34 PM, said:

Do you have a problem or question?

If you are getting error messages, post the complete error messages exactly as they appear in your development environment.


Jim

Hello
I have problem, becouse i don't know where from error and as can corect they
sorri for my very bed english
thnks

View PostBeRG, on 07 October 2012 - 01:50 PM, said:

View Postjimblumberg, on 07 October 2012 - 01:34 PM, said:

Do you have a problem or question?

If you are getting error messages, post the complete error messages exactly as they appear in your development environment.


Jim

Hello
I have problem, becouse i don't know where from error and as can corect they
sorri for my very bed english
thnks

show me this
1>------ Build started: Project: Ficha1, Configuration: Debug Win32 ------
1>Compiling...
1>Ficha1.cpp
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(22) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 8\vc\include\stdio.h(234) : see declaration of 'fopen'
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(28) : warning C4996: 'fscanf': This function or variable may be unsafe. Consider using fscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 8\vc\include\stdio.h(249) : see declaration of 'fscanf'
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(29) : error C2440: 'initializing' : cannot convert from 'float *' to 'size_t'
1> There is no context in which this conversion is possible
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(33) : error C2296: '+' : illegal, left operand has type 'float (__cdecl *)(float [],int)'
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(34) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(35) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(36) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(37) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(38) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(39) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(40) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(41) : warning C4244: '=' : conversion from 'float' to 'int', possible loss of data
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(49) : error C2446: '>=' : no conversion from 'float (__cdecl *)(float [],int)' to 'float'
1> There is no context in which this conversion is possible
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(49) : error C2440: '>=' : cannot convert from 'float (__cdecl *)(float [],int)' to 'float'
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(58) : error C2446: '<=' : no conversion from 'float (__cdecl *)(float [],int)' to 'float'
1> There is no context in which this conversion is possible
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(58) : error C2440: '<=' : cannot convert from 'float (__cdecl *)(float [],int)' to 'float'
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(68) : error C2086: 'int i' : redefinition
1> c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(11) : see declaration of 'i'
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(69) : error C2086: 'float inf' : redefinition
1> c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(15) : see declaration of 'inf'
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(69) : error C2440: 'initializing' : cannot convert from 'float (__cdecl *)(float [],int)' to 'float'
1> Context does not allow for disambiguation of overloaded function
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(70) : error C2086: 'float sup' : redefinition
1> c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(15) : see declaration of 'sup'
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(77) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(79) : error C2563: mismatch in formal parameter list
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(98) : error C2447: '{' : missing function header (old-style formal list?)
1>Build log was saved at "file://c:\Users\Vladimir\Desktop\Ficha1\Ficha1\Debug\BuildLog.htm"
1>Ficha1 - 12 error(s), 11 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is online

  • member icon


Reputation: 4074
  • View blog
  • Posts: 12,571
  • Joined: 25-December 09

Re: 12 errors

Posted 07 October 2012 - 03:10 PM

For your first two warnings I suggest you follow the advice given in the warning:

Quote

1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(22) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 8\vc\include\stdio.h(234) : see declaration of 'fopen'
1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(28) : warning C4996: 'fscanf': This function or variable may be unsafe. Consider using fscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1> c:\program files (x86)\microsoft visual studio 8\vc\include\stdio.h(249) : see declaration of 'fscanf'


For the next error:

Quote

1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(29) : error C2440: 'initializing' : cannot convert from 'float *' to 'size_t'

This error is referring to line 29, which should be:
        valores = new float [valores];

The variable valores is defined as a float*, you can't use a floating point value as an array size. Only integral values are allowed.

Next fix these errors and try to recompile. Remember that the warning messages tell you the line where the error was detected. Always fix the first error and recompile and repeat.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 Salem_c  Icon User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 1678
  • View blog
  • Posts: 3,180
  • Joined: 30-May 10

Re: 12 errors

Posted 07 October 2012 - 10:22 PM

> 029 valores = new float [valores];
Are you writing C or C++?
Because apart from this single line, the rest of the code is C.

> 1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(
Which means you should create a file called ficha1.c instead.
It will mean you'll get further errors when you try to sneak in bits of C++ without realising it (such as calls to new).
Was This Post Helpful? 0
  • +
  • -

#6 BeRG  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-October 12

Re: 12 errors

Posted 08 October 2012 - 02:32 AM

View PostSalem_c, on 07 October 2012 - 10:22 PM, said:

> 029 valores = new float [valores];
Are you writing C or C++?
Because apart from this single line, the rest of the code is C.

> 1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(
Which means you should create a file called ficha1.c instead.
It will mean you'll get further errors when you try to sneak in bits of C++ without realising it (such as calls to new).



It's C
Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,519
  • Joined: 23-August 08

Re: 12 errors

Posted 08 October 2012 - 02:38 AM

Well if it's C, then you can't use new and delete, you must use malloc and free. And give your file a name ending in .c rather than .cpp so that Visual Studio will compile it as C instead of C++.
Was This Post Helpful? 0
  • +
  • -

#8 BeRG  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-October 12

Re: 12 errors

Posted 09 October 2012 - 12:08 PM

I can do it :)

#include <stdio.h>
#include <math.h>


float menor(float lista[], int n);
float maior(float lista[],int n);


void main()
{
	int i,g;
	int b1,b2,b3,b4,b5,b6,b7,b8,b9;
	int frab[10]={0};
	float frel[10]={0};
	float inf, sup, p, a, c;
	int nlinhas;

	FILE *pfile;  // Apontador para uma estrutura de um ficheiro
	char nome_ficheiro[]= {"C:\\Users\\Vladimir\\Desktop\\(1)\\Ficha1\\DOC\\Teste.txt"};  // String com o nome do ficheiro
	float * valores;// Apontador para o Array dinamico que guarda os valores lidos do ficheiro

	pfile= fopen(nome_ficheiro, "r");

	if(pfile == NULL)
		printf("ERRO NA ABERTURA DO FICHEIRO");
	else
	{
		fscanf(pfile, "%d", &nlinhas);
		valores = new float [nlinhas];



		for (i=0; i<nlinhas; i++)
		{
			fscanf(pfile, "%f", &valores[i]);
		}



		p=(maior(valores, nlinhas) - menor(valores, nlinhas))/10;

		b1=menor(valores, nlinhas) + p;
		b2=b1 + p;
		b3=b2 + p;
		b4=b3 + p;
		b5=b4 + p;
		b6=b5 + p;
		b7=b6 + p;
		b8=b7 + p;
		b9=b8 + p;


		for (i=0; i<nlinhas; i++)
		{
			if (valores[i]>=menor(valores, nlinhas) && valores[i]<b1) ++frab[0];
		    else if(valores[i]>=b1 && valores[i]<b2) ++frab[1];
		    else if(valores[i]>=b2 && valores[i]<b3) ++frab[2];
		    else if(valores[i]>=b3 && valores[i]<b4) ++frab[3];
		    else if(valores[i]>=b4 && valores[i]<b5) ++frab[4];
		    else if(valores[i]>=b5 && valores[i]<b6) ++frab[5];
		    else if(valores[i]>=b6 && valores[i]<b7) ++frab[6];
		    else if(valores[i]>=b7 && valores[i]<b8) ++frab[7];
		    else if(valores[i]>=b8 && valores[i]<b9) ++frab[8];
		    else if(valores[i]>=b9 && valores[i]<=maior(valores, nlinhas)) ++frab[9];
		}

	}

	 i=0;
	 inf=menor(valores, nlinhas);
	 sup=p;


	printf("\n Limites \t Frequencia Absoluta \t Frequencia Relativa \t Grafico \n\n");

	do 	{
		a=nlinhas/100.00;
		c=float(frab[i])/a;

		frel[i]= c;

		printf(" %5.2f a %.2f\t            %d\t                  %3.2f\t      ",inf,sup,frab[i],frel[i]);

		for(g=1;g<=frab[i];++g)
		{				
			printf("*");
		}

		printf("\n");
		inf+=p;
		sup+=p;
		i++;

	}
	while(i<10);

	delete [] valores;
}

float menor(float lista[], int n)
{
	float min=lista[0];
	int i;
	for(i=1; i<n; i++)
	{
		if(lista[i]<min)
		{
			min=lista[i];
		}
	}
	return min;
}
float maior(float lista[],int n)
{
	float max=lista[0];
	int i;
	for(i=1; i<n; i++)
	{
		if(lista[i]>max)
		{
			max=lista[i];
		}
	}
	return max;
}

This post has been edited by Salem_c: 09 October 2012 - 12:22 PM
Reason for edit:: added [code][/code] tags - learn to use them yourself

Was This Post Helpful? 0
  • +
  • -

#9 Salem_c  Icon User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 1678
  • View blog
  • Posts: 3,180
  • Joined: 30-May 10

Re: 12 errors

Posted 09 October 2012 - 12:24 PM

View PostBeRG, on 08 October 2012 - 09:32 AM, said:

View PostSalem_c, on 07 October 2012 - 10:22 PM, said:

> 029 valores = new float [valores];
Are you writing C or C++?
Because apart from this single line, the rest of the code is C.

> 1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(
Which means you should create a file called ficha1.c instead.
It will mean you'll get further errors when you try to sneak in bits of C++ without realising it (such as calls to new).



It's C

Weird then that you're still using new/delete.
It's like you just ignored half of what was said.
Was This Post Helpful? 0
  • +
  • -

#10 BeRG  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 07-October 12

Re: 12 errors

Posted 09 October 2012 - 01:20 PM

View PostSalem_c, on 09 October 2012 - 12:24 PM, said:

View PostBeRG, on 08 October 2012 - 09:32 AM, said:

View PostSalem_c, on 07 October 2012 - 10:22 PM, said:

> 029 valores = new float [valores];
Are you writing C or C++?
Because apart from this single line, the rest of the code is C.

> 1>c:\users\vladimir\desktop\ficha1\ficha1\ficha1.cpp(
Which means you should create a file called ficha1.c instead.
It will mean you'll get further errors when you try to sneak in bits of C++ without realising it (such as calls to new).



It's C

Weird then that you're still using new/delete.
It's like you just ignored half of what was said.



Becouse it's beging. I'm study recently in university this language C. and i'm mistaken it's C++. sorry, but thanks for all help. it's relly very fast ansver :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1