Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12620 Discussions

Problem with reading from Uart

Altera_Forum
Honored Contributor II
1,308 Views

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 

 

Chase
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
378 Views

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];
0 Kudos
Altera_Forum
Honored Contributor II
378 Views

You also need to change this to: 

 

char Sonar_Height ; 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. 

 

Bill
0 Kudos
Altera_Forum
Honored Contributor II
378 Views

I see my mistake now. Thanks guys for your help it is much appreciated :)

0 Kudos
Reply