getString function problems

Hi evryone,

i'm having the two errors below and the debug will not give the line where is the problem, can someone guide me in the right direction?

thanks,

1) unresolved external symbol "char __cdecl getString(char *,char)" (?getString@@YADPADD@Z)
referenced in function _main

2) \Debug\get-test.exe : fatal error LNK1120: 1 unresolved externals





#include "stdafx.h"
#include <iostream>
using namespace std;


int main()
{
char getString(char *,char);
const int CHAR_SIZE=80;





char *array[CHAR_SIZE];
char sentence;
cout << "The number of sentences to enter: ";
cin >> sentence;
array[CHAR_SIZE] = new char[sentence];
getString (array[CHAR_SIZE], sentence);
delete [] array[CHAR_SIZE];
array[CHAR_SIZE] = 0;
return 0;
}

char *getString(char *array, int sentences)

{
cout << "Enter the sentences.\n";
for (int i=0;i<sentences;i++)
{
cout << "Sentence : " << endl << " are " << array[i];
}
return array;
}
you declared function char getString(char *,char);. when you call getString (array[CHAR_SIZE], sentence); compiler tries to find a char getString(char *,char);, but it does not exist. you defined char *getString(char *, int) instead.
Thanks, i've tried to fix it and now when i debug the program; the prompt come up which's "the number of sentences to enter" and when i type a number, the program crash and i've this message: Run-Time Check Failure #2 - stach around the variable array was corrupted.
how do you think i can correct this;

the way you deal with dynamic arrays is wrong.
it should be
1
2
3
4
5
char* array;
array = new char[CHAR_SIZE];
getString(array, sentence)
delete[] array;
array = 0;


also, since sentence is a char, when you enter 1 it will contain '1' which is actually 49. use int here.
Topic archived. No new replies allowed.