0

Approaching this question from a different angle, what character # could I use in my input file below:

1#2#3#/home/user/foo.txt
4#5#6#/home/user/foo.test.---.txt
7#8#9#/home/user/foo. .   .!!+.txt
...

Such that when I tokenize it (in C++ using strtok (str, "#") ) I am guaranteed that the file name will not break my program?

Community
  • 1
  • 1
puk
  • 16,318
  • 29
  • 119
  • 199
  • 4
    Doesn't matter, just pick a delimiter, and escape any existing delimiter characters already in the string. This is how strings can contain quotation marks. – user229044 Dec 16 '13 at 01:29
  • @meagar yes, but this is a program users are going to use, it would be a burden if they went around and escaped potentially hundreds of delimeters (especially if they are not programmers and do it in, for example, notepad) – puk Dec 16 '13 at 01:31

2 Answers2

3

Only two characters. The null byte '\0' and the slash '/'.

See Wikipedia:

In Unix-like file systems the null character, as that is the end-of-string indicator and the path separator / are prohibited.

But instead do what @meagar said, and escape whatever character you're using.

Christoffer Hammarström
  • 27,242
  • 4
  • 49
  • 58
0

As others have pointed out, the only guarantee is null or '/' but if you want to use something else, a less commonly used character in file names than comma, which is actually fairly common, would be the newline character.

shawnim
  • 580
  • 1
  • 6
  • 11
  • I actually thought about that, except that rows are separated by newlines. I could in theory use modular arithmetic, but it is just not intuitive to have it that way. I'll just put a note at the top not to use commas in file names – puk Dec 16 '13 at 01:49