Forum Discussion
Altera_Forum
Honored Contributor
16 years agoProblem with reading from Uart
I am getting the following warnings when I build my project
passing arg 1 of `fgets' from incompatible pointer type passing arg 1 of `fgets' makes pointer from integer without a cast The call to fgets is as follows... fgets( Sonar_Height , 4 , fp_uart); Sonar_Height is declared as a character array of size 3 char* Sonar_Height [3] fp_uart is the name of the file pointer to my uart Also i am getting the following warning char format, pointer arg (arg 2) Call to printf is as follows... printf( "Initial Sonar Height: %s\n" , Sonar_Height); Sonar_Height is the same variable as in fgets call. What do these warnings mean? Could they be the reason my read attempts from uart fail? Any assistance will be appreciated Chase3 Replies
- Altera_Forum
Honored Contributor
Hi Chase,
fgets requires a char* (pointer to char) as first parameter. Your Sonar_Height variable is a char** (pointer to a pointer to char). In order to have a 3 char array you must change to: char Sonar_Height [3]; - Altera_Forum
Honored Contributor
You also need to change this to:
fgets stores a NUL in the last position and you called fgets with a count of 4. When it writes the 0 to Sonar_Height [3] you will overwrite a byte, possibly the return address crashing this function. Billchar Sonar_Height ; - Altera_Forum
Honored Contributor
I see my mistake now. Thanks guys for your help it is much appreciated :)