Hello, I've got a function that returns a memory addres of an array. However making the char * static seems to be the only solution. However it since its static it doesnt get cleaned out so everything is kept.
#include <iostream> // cout << endl ...
#include <fstream> // for reading in the file ...
#include <cstring> // for comparing strings ...
using namespace std;
char temp[100]; // Global array to hold line by line
char * getsym();
void file_input(void);
int main()
{
char * a;
file_input();
a = getsym();
cout <<a;
a = getsym();
cout << a;
return 0;
}
//sorts out the temp array and returns tokens.
char * getsym()
{
char buffer[10];
char ch;
cout << "getting the next token" << endl;
static int i = 0;
ch = temp[i];
if(!isdigit(ch))
{
while(isalpha(ch))
{
buffer[i] = ch;
cout << "***Is alpha function called *** " << endl;
i++;
ch = temp[i];
}
return buffer;
}
if(!isalpha(ch))
{
while(isdigit(ch))
{
buffer[i] = ch;
cout << "***Is digit function called *** " << endl;
i++;
ch = temp[i];
}
return buffer;
}
if(ch == '+')
{
cout << "\nLanguage symbol found = " << ch << endl;
buffer[0] = '+';
return (buffer);
}
if(ch == '$')
{
cout << "\nReserved symbol found = " << ch << endl;
i++;
}
return NULL;
}
I've got a theory of how to fix it. put a for loop in that loops round 10 times filling it with. Err Don't know. Can anyone help with this? point me in the right direction ? (no pun intended? )
Thanks.