/* < newton.c > */
#include "smp.h"

main()
{
	void USERF(double *,double *,double);
	double 	x0,e;
	int		n,NMAX;

/*** ステップ1 データの入力 ***/
	printf("\n初期値 x0 = ");
	scanf("%1f",&x0);
	printf("\n収束判別定数 p = ");
	scanf("%1f",&e);
	printf("\n最大反復回数 NMAX = ");
	scanf("%d",&NMAX);

/*** ステップ2 ニュートン・ラプソン法の計算 ***/
	S_NEWT(&n,&x0,e,NMAX,USERF);

/*** ステップ3 計算結果の出力 ***/
	printf("\n反復回数:N=%d 解:X(N)=%10.71e",n,x0);
}

/* < ニュートン・ラプソン法の関数 > */
void S_NEWT(int *n,double *x0,double e,int NMAX,double (*FUNC)())
/*	n		: スカラー	反復回数		(Out)
	x0		: スカラー	初期値(解)		(In/Out)
	e		: スカラー	収束判別定数	(In)
	NMAX	: スカラー	最大反復回数	(In)
	FUNC	:			ユーザ定義関数	(In)	*/
{
     double fun,dfun,xn,ans;
     for(*n=0,xn=*x0;*n<NMAX;){
		(*FUNC)(&fun,&dfun,xn);
		*x0=xn-fun/dfun;
		if(fabs(xn-*x0)>e)
	    	xn=*x0;
	else
	    break;
      }
}

/* <ユーザ定義の関数とその微分の関数 > */
void USERF(double *fn,double *dfn,double x)
/*	fn	: スカラー	方程式			(Out)
	dfn	: スカラー	方程式の微分	(Out)
	x	: スカラー	入力値			(In)	*/
{
	double x2;
	x2=x*x;
	*fn=x2*x-1.0;
	*dfn=3.0*x2;
	return;
}

I dont know where is the problem, anyone see anything ?
sorry for the japanese language

there were errors on

in function 'main'
and incompatible pointer type on line 19

Was that all the errors? Having the complete text of the error messages would help (unless that's also in Japanese).

I couple of points

main returns int, returning default int without a warning tends to suggest you are using an old compiler.

Using capital letters for you function names is a little unusual, I assumed they were macros at first, however it is not actually wrong.

You do not seem to have declared S_NEWT before trying to call it. That may be having an effect as the compiler will not know what the function prototype is.

Firstly its a warning not an error, the program still compiled and possibly worked. However that said plenty of programmers use the rule of thumb that all warning should be dealt with and the program should compile without warnings.

You have declared S_NEWT as taking a pointer function with no parameters but supplied it with a pointer to a function that takes 3 parameters. Try fixing the prototype of S_NEWT to take account of the 3 parameters in USERF.

Banfa>>can u tell me how could i do that?
can u do it for me, pls, seriously i dont understand C++ but i have to submit this report this week

Here is your function S_NEWT with the code removed and the relevant parameter highlighted

void S_NEWT(int *n,double *x0,double e,int NMAX,[b]double (*FUNC)()[/b])
{
   <snip>
}

The () at the end of the highlighted parameter represents the parameter list for the function pointer FUNC.

Here is the prototype of your function USERF

void USERF(double *,double *,double);

The parameter list is everything between ( and ). () and (double *,double *,double) are not equivalent, you need to alter the () in your function S_NEWT to match what is in USERF.

This needs to be done both where S_NEWT is declared and defined.

can you just correct the code and paste here,
seriously i dont get it..
im stupid !

hiiiii...

which is the biggest data type supportd by mysql???
how shud i use scanf wit "long double"....wat is the %_????

i dont write it, i just copy from the book. help me!!
i dont understand and i dont learn it from basic...
u must help me banfa!!!

i dont know.. i just copy from the text book,
i dont learn programing from basic,
please help me banfa,!!!

i dont know.. i just copy from the text book,
i dont learn programing from basic,
please help me banfa,!!!

You sound desperate. Please note that even if Banfa gives you the solution to it, you still won't get it AT ALL, because you won't be knowing what he is talking about.
The problem your facing is due to invalid parameter of function.

double (*FUNC)()

This parameter will equal to a function like:

double doSomething();

but what you are passing is:

void USERF(double *,double *,double);

They don't match AT ALL!
So, change your parameter to accept USERF.

void (*FUNC)(double *,double *,double)

Please learn what you are doing, rather blatantly copying from textbooks.

Edited 6 Years Ago by nbaztec: n/a

Comments
Ta

so do i need to replace void USERF(double *,double *,double); with
void (*FUNC)(double *,double *,double) ?

i did that but more error

In future always post it rather PM me. This way everyone can get to know of your problem & contribute accordingly.

i did that but more error

Where exactly did you make that change? You have to change the parameter of S_NEWT() not the signature of USERF()

EDIT: Don't be lazy & define main as int main & always return a value.
EDIT: Pass a Reference to the function &USERF.

Edited 6 Years Ago by nbaztec: n/a

main()
{
	void USERF(double *,double *,double);
.
.
}

You can't declare functions-in-functions in C, perhaps in JavaScript or Pascal but not in C/C++. Take that declaration outside main().

sorry, seriously u need to tell exactly what should i do
i am stupid and i dont get it
i dont learn programming at all, and i dont know anything, but i donno why i have to do this

Where exactly did you make that change? You have to change the parameter of S_NEWT() not the signature of USERF()

EDIT: Don't be lazy & define main as int main & always return a value.
EDIT: Pass a Reference to the function &USERF.

i dont get it, can u just paste the code.

but i donno why i have to do this

Huh? You didn't want to do this?
OK to end this:

.
void USERF(double *,double *,double);
void S_NEWT(int *n,double *x0,double e,int NMAX,void (*FUNC)(double *,double *,double));
.
int main()
{
  S_NEWT(&n,&x0,e,NMAX,&USERF);
  return 1;
}
void S_NEWT(int *n,double *x0,double e,int NMAX,void (*FUNC)(double *,double *,double))
{
.
.
}
void USERF(double *,double *,double)
{
.
.
}

EDIT: I recommend you to start using the Edit feature, it's a lot neater that way & posts don't appear to be spams.

Edited 6 Years Ago by nbaztec: n/a

main()
{
	void USERF(double *,double *,double);
.
.
}

You can't declare functions-in-functions in C, perhaps in JavaScript or Pascal but not in C/C++. Take that declaration outside main().

what????

why just can u copy the codes and paste it here, actually i dont have to do the prog but i need the prog to calculate something, and the teacher just want us to copy the prog but the prog from the book is not working, very stupid whoever wrote the code, and the book

the prog from the book is not working, very stupid whoever wrote the code, and the book

Apparently yes. Books should be properly scrutinized before they are published.

what????

What's no to get in that. From now on at least be serious in your classes.

/* < newton.c > */
#include "smp.h"

main()
{
	void USERF(double *,double *,double);
	double 	x0,e;
	int		n,NMAX;

/*** ステップ1 データの入力 ***/
	printf("\n初期値 x0 = ");
	scanf("%1f",&x0);
	printf("\n収束判別定数 p = ");
	scanf("%1f",&e);
	printf("\n最大反復回数 NMAX = ");
	scanf("%d",&NMAX);

/*** ステップ2 ニュートン・ラプソン法の計算 ***/
	S_NEWT(&n,&x0,e,NMAX,USERF);

/*** ステップ3 計算結果の出力 ***/
	printf("\n反復回数:N=%d 解:X(N)=%10.71e",n,x0);
}

/* < ニュートン・ラプソン法の関数 > */
void S_NEWT(int *n,double *x0,double e,int NMAX,double (*FUNC)())
/*	n		: スカラー	反復回数		(Out)
	x0		: スカラー	初期値(解)		(In/Out)
	e		: スカラー	収束判別定数	(In)
	NMAX	: スカラー	最大反復回数	(In)
	FUNC	:			ユーザ定義関数	(In)	*/
{
     double fun,dfun,xn,ans;
     for(*n=0,xn=*x0;*n<NMAX;){
		(*FUNC)(&fun,&dfun,xn);
		*x0=xn-fun/dfun;
		if(fabs(xn-*x0)>e)
	    	xn=*x0;
	else
	    break;
      }
}

/* <ユーザ定義の関数とその微分の関数 > */
void USERF(double *fn,double *dfn,double x)
/*	fn	: スカラー	方程式			(Out)
	dfn	: スカラー	方程式の微分	(Out)
	x	: スカラー	入力値			(In)	*/
{
double x2;
x2=x*x;
*fn=x2*x-1.0;
*dfn=3.0*x2;
return;
}

i copy this code so can you help me replace where should i put the code , because when i do that, the error come out, and im very tired with this ,
can you replace that and paste it here?
i really appriciate your help

Edited 6 Years Ago by whattever: n/a

Huh? You didn't want to do this?
OK to end this:

.
void USERF(double *,double *,double);
void S_NEWT(int *n,double *x0,double e,int NMAX,void (*FUNC)(double *,double *,double));
.
int main()
{
  S_NEWT(&n,&x0,e,NMAX,&USERF);
  return 1;
}
void S_NEWT(int *n,double *x0,double e,int NMAX,void (*FUNC)(double *,double *,double))
{
.
.
}
void USERF(double *,double *,double)
{
.
.
}

EDIT: I recommend you to start using the Edit feature, it's a lot neater that way & posts don't appear to be spams.

i dont know where to put this code, which line, tired of eror comes out

Please show me the code. From what I get you change the signature of S_NEWT() upon declaration but not upon defining it.

/* < newton.c > */
#include "smp.h"

int main()
{
	void USERF(double *,double *,double);
	void S_NEWT(int *n,double *x0,double e,int NMAX,void (*FUNC)(double *,double *,double));
	double 	x0,e;
	int		n,NMAX;

/*** ステップ1 データの入力 ***/
	printf("\n初期値 x0 = ");
	scanf("%1f",&x0);
	printf("\n収束判別定数 p = ");
	scanf("%1f",&e);
	printf("\n最大反復回数 NMAX = ");
	scanf("%d",&NMAX);

/*** ステップ2 ニュートン・ラプソン法の計算 ***/
	S_NEWT(&n,&x0,e,NMAX,&USERF);
	return 1;

/*** ステップ3 計算結果の出力 ***/
	printf("\n反復回数:N=%d 解:X(N)=%10.71e",n,x0);
}

/* < ニュートン・ラプソン法の関数 > */
void S_NEWT(int *n,double *x0,double e,int NMAX,void (*FUNC)(double *,double *,double))
/*	n		: スカラー	反復回数		(Out)
	x0		: スカラー	初期値(解)		(In/Out)
	e		: スカラー	収束判別定数	(In)
	NMAX	: スカラー	最大反復回数	(In)
	FUNC	:			ユーザ定義関数	(In)	*/
{
     double fun,dfun,xn,ans;
     for(*n=0,xn=*x0;*n<NMAX;){
		(*FUNC)(&fun,&dfun,xn);
		*x0=xn-fun/dfun;
		if(fabs(xn-*x0)>e)
	    	xn=*x0;
	else
	    break;
      }
}

/* <ユーザ定義の関数とその微分の関数 > */
void USERF(double *fn,double *dfn,double x)
/*	fn	: スカラー	方程式			(Out)
	dfn	: スカラー	方程式の微分	(Out)
	x	: スカラー	入力値			(In)	*/
{
double x2;
x2=x*x;
*fn=x2*x-1.0;
*dfn=3.0*x2;
return;
}

Edited 6 Years Ago by whattever: n/a

int main()
{
	void USERF(double *,double *,double);
	void S_NEWT(int *n,double *x0,double e,int NMAX,void (*FUNC)(double *,double *,double));

Please see my above post regarding this.

This question has already been answered. Start a new discussion instead.