Thread: Strings...
View Single Post
  #4  
Old 06-09-2002, 05:33 AM
theCoder
Sarnak
 
Join Date: Jan 2002
Posts: 90
Default

man is a command you can use to find information about various things, from other commands to system calls and more. man is short for manual, but it's only available (AFAIK) on UNIX style systems (Linux, MacOSX, etc).

As far as finding the "00" in a null terminated string, you'll probably want to use strstr. strstr takes two parameters: the string to search and the string to search for. It returns a pointer to the position in the first string where the second string is located (or NULL if it's not found). For example:
Code:
char[256] name = "Some name00";
char* found = strstr(name, "na");
printf("%s\n", found);
Would print out "name00". In this case, found is actually equal to name+5 in terms of pointer math. It can get confusing if you don't understand how pointers work. I'd suggest you find some reference that explains pointers in c/c++.

To better answer your original question, however, if you wanted to delete the "00" in the name above, you would strstr for "00" and if it was found (return value is not NULL), then deference the pointer and set it to '\0' (the null character):
Code:
char* found = strstr(name, "00");
if (found != NULL) *found = '\0';
printf("%s\n", name);
Now it prints out "Some name".

Also, if you do change the data in the string, you should be sure to copy it first or it will change the data in the class (which you probably don't want )

HTH
Reply With Quote