Skip to content

Instantly share code, notes, and snippets.

@ayaderaghul
Last active February 17, 2018 16:00
Show Gist options
  • Save ayaderaghul/bda3402789cf39cba54b0e8647751c58 to your computer and use it in GitHub Desktop.
Save ayaderaghul/bda3402789cf39cba54b0e8647751c58 to your computer and use it in GitHub Desktop.
sudoku: to get input and convert into array of numbers..
#include <stdio.h>
#include <stdlib.h>
int length(char *str)
{
int i;
i = 0;
while (str[i])
++i;
return (i);
}
// check if a cell contains a number?
char check_number(char c)
{
return((('0' <= c) && (c <= '9')) ? c : '0');
}
// inside solve..
// put into array
void solve (char **str)
{
//char **array[9][9] = malloc(81 * sizeof(char));
char array[9][9];
int i;
int j;
i = 0;
while (i < 9)
{
j = 0;
while (j < 9)
{
array[i][j] = check_number(str[i][j]);
++j;
}
++i;
}
}
// main
int main(int argrc, char **argrv)
{
if (argrc != 10)
{
printf("Error\n");
}
else
{
int i;
int l;
i = 1;
l = 0;
while (i < argrc)
{
l = l + length(argrv[i]);
++i;
}
if (l != 81)
printf("Error\n");
else
{
char **array[9][9];
solve(argrv);
}
return (0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment