Hi,
Why does the following code seg fault before returning:
int main()
{
char iD[20];
memset (iD, 0, 20);
char* prefix;
srand (time(NULL) );
int iPrefix = rand()%1000000;
sprintf(prefix, "%i", iPrefix);
int len = strlen(prefix);
char* staticChar = "123456789";
//set prefix into ID
memcpy(iD, prefix, len);
// append static value
memcpy(iD+len, staticChar, 20-len);
cout << "END " << endl;
return 0;
}
At the minute, the cout will display, but I get a segmentation fault.