in reply to how do I remember the trailing /

If you use a system("ls -F > data") you will get the trailing \. Note that you will also get the other trailing symbols as well. The man page for "ls" excerpt:
-F Marks directories with a trailing slash (/), doors with a trailing greater-than sign (>), executable files with a trailing asterisk (*), FIFOs with a trailing vertical bar (|), symbolic links with a trailing at-sign (@), and AF_UNIX address family sockets with a trailing equals sign (=).
I suspect that the user account you were using at the console has an alias in the startup files or is possibly defined at a higher system level to default the -F switch. I would think that you would be getting the same results if the latter were true or if you were logged in as the same user and performed both tasks.

Update: Hofmator is probably closer to the mark. i.e., -p instead of -F