Archive for April, 2008

gcc: error: stray ‘\342’ in program

Thursday, April 17th, 2008
Lately I have been worried about a strange error message I have been getting from gcc, while trying to compile small C programs for my school's assignment.

The errors were of this form:

giannis@giannis-vbox:~$ gcc program.c
program.c: In function ‘main’:
program.c:57: error: stray ‘\342’ in program
program.c:57: error: stray ‘\200’ in program
program.c:57: error: stray ‘\234’ in program
program.c:57: error: stray ‘\’ in program
...


I couldn't see any obvious syntactical error in the mentioned line. This is how line #57 looks like:

printf(“\nThe linked list representation is...\n”);

At first sight, it looks pretty fine, but if you look closely you will see that the double quotation marks that surround the string literal are not the neutral (vertical) ones (like this: "). They are left and right double quotation marks respectively.

If I replace the quotation marks with the neutral ones, like this:

printf("\nThe linked list representation is...\n");

the problem is solved. So, if you are getting this kind of error maybe you should look closely to any double (or single) quotation marks in the erroneous line.

It is worth to say that I only had this problem when copying and pasting from the PDF files of my school, which were mostly likely exported by Micro$oft Word, which in turn had probably screwed the double quotation lines.

VirtualBox: access Windows-host shared folders from Ubuntu-guest

Wednesday, April 9th, 2008
This is the scenario that you run Windows as your host operating system and Ubuntu in a VirtualBox, and that you want to access a specific Windows folder from Ubuntu.

First you have to make sure that have install Guest Additions. From the VirtualBox's menu go to Devices → Install Guest Additions... This will mount a virtual CD on your /media/cdrom. Normally this folder's window will show up. As root run the program VBoxLinuxAdditions.run. When the program completes reboot your VirtualBox.

With Guest Additions installed you may now go ahead and define the shared folder(s). From the VirtualBox's menu go to Devices → Shared Folders. A dialog will show up. In this dialog you can specify which folder from your Windows system you want to share with your Ubuntu. Press the button with the + symbol to add a new shared folder in the list. You will have to specify a Folder Name for each folder you add. Make sure you memorize that name because you will need it very soon.

When done with you shared folder(s) specification, you may now go ahead and actually mount these folders from Ubuntu. First you have to create a mounpoint, that is, a directory in your Ubuntu which will reflect the shared folder from Windows:

# sudo mkdir /media/windows-share

Of course you may choose an alternative path for your mountpoint. With your mountpoint created you can now mount the shared folder, like this:

# sudo mount -t vboxsf folder-name /media/windows-share

Where folder-name will be the name you assigned for this folder when you were adding it in the shared folders list.

You could use the /etc/init.d/rc.local script to execute these commands on startup to have the shared folders automatically mounted every time you start your Ubuntu VirtualBox.

JSP: how to read unicode from forms

Sunday, April 6th, 2008
Are you having encoding problems while trying to read multilingual data from a JSP form? That is because JSP by default is trying to interpret your input as ISO-8859-1. That's fine unless you have a form that sendsUTF-8.

The problem can be eliminated by simply adding the following line of before you do any calls to getParameter():

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
...
request.setCharacterEncoding("utf-8");
...
}