revised code
Code:
#include<iostream>
using namespace std;
const char* letters[] = {
"ABC",
"DEF",
"GHI",
"JKL",
"MNO",
"PRS",
"TUV",
"WXY"
};
FILE* fp;
char str1[15];
void GenCombinations (
const char* number,
char str[])
{
if (*number == '\0')
{
fwrite(str - 8, 1, 8, fp);
cout<<str<<endl;
fwrite("\r\n", 1, 2, fp);
return;
}
else if (*number == '-')
{
GenCombinations(number + 1, str);
}
else
{
const int group = *number - '0' - 2;
char fullstr[3] = "";
for (int i = 0; i < 3; i++)
{
*str = letters[group][i];
strcat(fullstr,str);
}
cout<<fullstr<<endl;
}
GenCombinations(number + 1, str + 1);
}
int main()
{
char str2[]="42472888";
//strcat("\0",str2);
GenCombinations(str2,str1);
cout<<str1<<endl;
return 0;
}