Path to usb device in Linux

Hello,
I have c++ application that needs to write/read to/from usb device.

I don’t know how I can determine the path of current usb device via my application.

Currently I use hard-coded path “/media/sda1/”, but sometimes it is mounted to other devices.

Any hint how to find it out?

Thank you

Is the program always writing to the same device? If so, you may want to make an entry in /etc/fstab for the device such that it is mounted where you want it with the desired flags, etc. This will give your program a static location for which it can access the mounted filesystem.

Additional information about fstab

Update:

There are actually two mechanisms in our standard LXDE Linux image which can automount storage devices: udisks & an automount udev rule. udisks makes proper use of fstab; however, the udev rule appears to ignore fstab. Therefore, I recommend removing (or moving) the automount udev rule to ensure udisks handles automounting:

rm /etc/udev/rules.d/automount.rules