I have a set of entries; each entry contains a unique name (C string). When creating new entry user may provide a unique name for the entry or may not. In case of user not providing a name, I have to generate a default unique name. I wanted to count the number of entries, increment it and use it as index for the new entry's unique name, but this name may already exist. What are some other ways to generate a truly unique name in my case?
Store all the names that you already have in a hash table. Generate the new name using the algorithm that you described, then check uniqueness by doing a hash lookup. If the name is already in use, increment the number and try again; continue until you find a name that has not been taken.
Note: the problem exists only because you let users enter unique names. If you generate all your unique strings programmatically, you wouldn't have to do a duplicate check: keeping a running total of the number of entries would be sufficient.