- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ChaseLink Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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];- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I see my mistake now. Thanks guys for your help it is much appreciated :)
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page