So to describe my code, my scanCode function reads in from a text file to produce an array called "array" in the main function which is 2D holding strings one, two, three etc until nine. My problem is in the converter function because I want to convert the words corresponding to its actual digits so one to 1, two to 2 in an int array. But there is something wrong with my code which I just cannot find out because the run cmd keeps freezing ! Could debug and tell me what is wrong with my converter function?
#include <stdio.h>
char** scanCode()
{
FILE *in_file;
int i = 0;
static char scan[9054][6];
in_file = fopen("message.txt", "r");
while (!feof(in_file))
{
fscanf(in_file,"%s", scan[i]);
//printf("%s", scan[i]);
i++;
}
return scan;
fclose(in_file);
}
int* converter(char** array)
{
int j = 0;
static int his[9053];
int i = 9053;
for (j=0;j<i;j++)
{
if ((strcmp(array[j], "one")) == 0)
{
his[j] = 1;
}
else if ((strcmp(array[j], "two")) == 0)
{
his[j] = 2;
}
else if ((strcmp(array[j], "three")) == 0)
{
his[j] = 3;
}
else if ((strcmp(array[j], "four")) == 0)
{
his[j] = 4;
}
else if ((strcmp(array[j], "five")) == 0)
{
his[j] = 5;
}
else if ((strcmp(array[j], "six")) == 0)
{
his[j] = 6;
}
else if ((strcmp(array[j], "seven")) == 0)
{
his[j] = 7;
}
else if ((strcmp(array[j], "eight")) == 0)
{
his[j] = 8;
}
else if ((strcmp(array[j], "nine")) == 0)
{
his[j] = 9;
}
else{
his[j] = 0;
}
printf("%d",his[j]);
}
return his;
}
int main(void)
{
int i = 9054;
int d = 0;
int j = 0;
int b = 0;
int a = 0;
int c = 0;
//int hi[9053];
int final[3018];
int veryfinal[1509];
char ( *array )[6] = scanCode();
int *hi = converter(array);
while(1);
return 0;
}
Basically it freezes when I run it, I think it has definitely to do something with the converter function but I just don't know what but I get these little warnings
17 1 [Warning] return from incompatible pointer type
85 25 [Warning] initialization from incompatible pointer type
87 24 [Warning] passing argument 1 of 'converter' from incompatible pointer type
21 6 [Note] expected 'char **' but argument is of type 'char (*)[6]'
but obviously it runs despite these warnings and notes