Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C "Expected Expression" error with Xcode

I am trying to compile this code example from the book "Head First C" (page 50), and Xcode gives me the error "Parse Issue" "Expected Expression" and highlights the line "int longitude = -64;" in red.

#include <stdio.h>

void go_south_east(int * lat, int * lon)
{    
    *lat = *lat - 1;
    *lon = *lon + 1;
}

int main()
{
   int latitude = 32;
   int longitude = -64;
   go_south_east(&latitude,&longitude);
   printf("Avast! Now at: [%i, %i]\n", latitude, longitude);
   return 0;
}

I have no idea why. Can anyone help?

like image 552
Magwich Avatar asked Jul 09 '12 01:07

Magwich


1 Answers

Sometimes when copying code from PDFs invisible unwanted characters are copied as well.

To fix this you can tell Xcode to show you all invisible characters by changing the editor properties from the top bar menu.

(top bar menu) → Editor → Show Invisibles

You will have to delete anything that looks strange strange, like a space being represented by an actual space (" ") or a little triangle ("^"). Keep in mind that in this mode spaces are represented with this symbol "⌴".

For example:

Sample invisible bad character

Which causes the "Expected Expression" error.

like image 181
Pochi Avatar answered Oct 01 '22 01:10

Pochi