Passing a "char[]" in a function

Hi,

I'm having trouble getting the function to work here.

ERROR =
Error C2664 'void oLokumRates(int,int,int,bool,char [])': cannot convert argument 5 from 'const char [14]' to 'char []'


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

void oLokumRates(int, int, int, bool, char[]);

int main(void){
oLokumRates(1, Duration, 1, FALSE, "LokumTest.csv");
return 0;
}
void oLokumRates(int tot_scen, int dur_periods, int x1, bool rw_switch, char *charname) //tot_scen = Total Scenarios, zz = Duration, x1 = file number appended
{
	//Check the projected rates here...
	int k, i, j;
	FILE *infile;
	char temp_name[1000];
	char buf[12];
	_itoa_s(x1, buf, 10);
	strcpy_s(temp_name, cRunLocation);
	strcat_s(temp_name, charname);
	strcat_s(temp_name, buf);
	strcat_s(temp_name, ".csv");
	errno_t err;
	err = fopen_s(&infile, temp_name, "w");
	if (infile == NULL) { exit(0); }

	fputs("iteration,period,short_rate,nom_rate_5yr,nom_rate_10yr,beta,S&P_return,Bond_return,Russell_return,EAFE_return,Money_return\n", infile);
	for (i = 1; i <= tot_scen; i++)
	{
		for (j = 0; j <= dur_periods; j++)  //seperate phlvic, plic 05152009
		{
			fprintf_s(infile, "%d,", i);
			fprintf_s(infile, "%d,", j);
			if (rw_switch == TRUE)
			{//LokumFIXED

			}
			else
			{
				fprintf_s(infile, "%.12lf,", LokumFIXED[i][j]);
				fprintf_s(infile, "%.12lf,", LokumRate5[i][j]);
				fprintf_s(infile, "%.12lf,", LokumUST7[i][j]);
				fprintf_s(infile, "%.12lf,", LokumBeta[i][j]);
				fprintf_s(infile, "%.12lf,", LokumUS[i][j]);
				fprintf_s(infile, "%.12lf,", LokumAGGR[i][j]);
				fprintf_s(infile, "%.12lf,", LokumSMALL[i][j]);
				fprintf_s(infile, "%.12lf,", LokumINTL[i][j]);
				fprintf_s(infile, "%.12lf", LokumMONEY[i][j]);
			}
			fputs("\n", infile);
		}
	}
	fclose(infile);//Close File
}
"strings" are const.

So perhaps
 
void oLokumRates(int, int, int, bool, const char[]);


And do the same to the implementation.

Oh, so you don't have to keep scrolling horizontally as well as vertically, you can write really long strings like this.
1
2
3
4
	fputs("iteration,period,short_rate,nom_rate_5yr,"
              "nom_rate_10yr,beta,S&P_return,Bond_return,"
              "Russell_return,EAFE_return,Money_return\n", infile);

The compiler will automatically join back to back string constants for you.
I'm still getting the errors:

Severity Code Description Project File Line Suppression State
Error LNK1120 1 unresolved externals

Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "void __cdecl oLokumRates(int,int,int,bool,char const * const)" (?oLokumRates@@YAXHHH_NQBD@Z) referenced in function "void __cdecl ModelOffice(void)" (?ModelOffice@@YAXXZ) Blank

My call is still:

oLokumRates(1, Duration, 1, FALSE, "LokumTest.csv");
Last edited on
Well it looks for all the world like you only changed the prototype, and not the implementation.

I did say change both.

They have to be consistent, otherwise the compiler things they're two different functions.
OK, thanks!

Works now...
Last edited on
Topic archived. No new replies allowed.