Reputation: 153
I get the warning Return from incompatible pointer type in line where I return sarray, why though? I have been trying to figure out for a while now.. I also get a warning for incompatible pointer type in line
( *iarray )[CHARACTER_LIMIT] = scanCode();
but I think if I fixed the first part, this would be easier to fix this one.
#include <stdio.h>
#define MAX_WORDS 9054 //Scope variables
#define CHARACTER_LIMIT 6
#define MAX_TRIPLETS 3018
char** scanCode(void)
{
FILE *in_file;
int i = 0;
static char sarray[MAX_WORDS][CHARACTER_LIMIT];
in_file = fopen("message.txt", "r");
for(i=0; i<WORD_COUNT_MAX; i++) {
fscanf(in_file,"%s", sarray[i]);
}
return sarray;
fclose(in_file);
}
int main(void)
{
char ( *iarray )[CHARACTER_LIMIT] = scanCode();
while(1);
return 0;
}
Upvotes: 0
Views: 1939
Reputation: 227370
sarray
is an array or arrays, which can decay to pointer to array, but not pointer to pointer. Converting sarray
to char**
should be an error.
Besides that, scanCode()
returns a pointer to pointer to char
. iarray
is a pointer to array of char
with length CHARACTER_LIMIT
. These are not the same type, and the compiler is warning you about this.
You need to change either the return type of the function:
char (*scanCode(void))[CHARACTER_LIMIT] {
....
return sarray;
}
Here, sarray
decays to a pointer to array of length CHARACTER_LIMIT
.
Upvotes: 2