Abraham Abraham - 1 month ago 11
C++ Question

Error: stray '\240' in program

It is wanted of me to implement the following function:

void calc ( double* a, double* b, int r, int c, double (*f) (double) )


Parameters a, r, c and f are input and b is output. “a” and “b” are 2d matrices with “r” rows and “c” 
columns. “f” is a function pointer which can point to any function of the following type:

double function‐name ( double x ) { 
    … 



Function 
calc
 converts every element in matrix a, i.e., aij, to bij=f(aij) in matrix b.  




I implement the
calc
function as follows, and put it in a program to test it:

#include <stdlib.h>
#include <iostream>

using namespace std;

double f1( double x ){
return x * 1.7;
}

void calc ( double* a, double* b, int r, int c, double (*f) (double) ) 
{
double input;
double output;

for(int i=0;i<r*c;i++)
{
input=a[i];
output=(*f)(input);
b[i]=output;
}
}

int main()
{
//input array:
int r=3;
int c=4;
double* a = new double[r*c];
double* b = new double[r*c];

//fill "a" with test data
//...

for (int i=0;i<r*c;i++)
{
a[i]=i;
}


//transform a to b
calc ( a, b, r, c, f1 );

//print to test if the results are OK
//...

for (int i=0;i<r*c;i++)
{
b[i]=i;
}

return 0;
}


The problem is, I can't compile it. This is the output of DevC++ when I click on Compile and Execute button :

compilation errors referring to invalid characters

What's wrong?

I appreciate any comment to make the implementation more efficient.

Answer

It appears you have illegal characters in your source. I cannot figure out what character \240 should be but apparently it is around the start of line 10

In the code you posted, the issue does not exist: Live On Coliru