Skip to content

Instantly share code, notes, and snippets.

@toanalien
Created July 21, 2015 04:28
Show Gist options
  • Save toanalien/1b7a17e1067061572a26 to your computer and use it in GitHub Desktop.
Save toanalien/1b7a17e1067061572a26 to your computer and use it in GitHub Desktop.
Letter Combinations of a Phone Number
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**
* Return an array of size *returnSize.
* Note: The returned array must be malloced, assume caller calls free().
*/
int slip_num(int num)
{
int temp = 0;
while (num/10!=0)
{
temp+=num%10;
temp*=10;
num = num/10;
}
temp+=num;
return temp;
}
void Try(int num)
{
int letter [] = {97,100,103,106,109, 112,116,119};
int temp = num%10;
temp-=2;
char *result;
char buffer [33];
//printf("%d", letter[2]);
for (int i = 0; i<letter[temp+1]- letter[temp]; i++)
{
printf("%c", letter[temp]+i);
//strcat(result, itoa(letter[temp]+i,buffer, 10));
if(num/10!=0)
Try(num/10);
else
printf("\n");
}
}
void letterCombinations(int digits, int* returnSize=0) {
//char letter[8][4] = {('a', 'b', 'c'), ('d','e','f'), ('g','h','i'),('j','k','l'), ('m','n','o'), ('p', 'q', 'r', 's'), ('t','u','v'), ('w','x', 'y','z')};
int i =1, temp;
temp = digits;
//char **result;
/*
while (temp/10!=0)
{
i++;
temp /=10;
}
*/
}
int main()
{
char digits[] = "\"23\"";
char *pch;
pch = digits+1;
strncpy(pch, digits+1,strlen(digits+1)-1);
pch[strlen(pch) ] = '\0';
int num = atoi(pch);
//printf("%d", num);
//letterCombinations(num);
//printf("%d", slip_num(1));
num = slip_num(num);
Try(num);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment