umm guys i don't understand this function....could someone explain to me how it works??
and how it returns a pointer value...thanks
umm guys i don't understand this function....could someone explain to me how it works??
and how it returns a pointer value...thanks
http://www.cplusplus.com/reference/c...ng/strchr.html
Is it clearer ?
I hate real numbers.
umm thanks to that reply....sorry i don't get that....do you know where could i find the details of that function?? i mean i could see all the contents of that function...so that i could understand...thanks a lot...
Yes, the GNU Standard C library is open source (glibc) -> http://www.gnu.org/software/libc/
Of course that's just one implementation... other libraries/systems may do it differently but *should* work exactly the same -- according to the standards.
It's just a while loop that
- compares with the character you passed
- compares with \0
It stops when it reaches either one.
What else do you need to know - it's about as basic as it gets when it comes to string processing.
The only thing lower than this is strlen(), have you figured out that one yet?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Example:
What does it look like it is doing?Code:#include <stdio.h> #include <string.h> int main(void) { const char *s = "Hello world! I am a big string to use to show what strchr() does."; const char *t = s; for(;t; t = strchr(t, ' ')) printf("%s\n", t); return 0; }
I prefer to write for-loops like this:
--Code:#include <stdio.h> #include <string.h> int main(void) { const char *s = "Hello world! I am a big string to use to show what strchr() does."; const char *t; for(t = s;t; t = strchr(t, ' ')) printf("%s\n", t); return 0; }
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
As do I, however I do like initializing my variables up front so I just ended up writing my code like that. So... in a nutshell, duly noted my nit-picking friend.
Thanks a lot.....Thank you3x.....
You are welcome, sick. I hope you understand how useful strchr() can be now. Unlike strtok() it doesn't alter your input data. There is a function strrchr() that I use for a lot of things... like parsing out paths. It does the same thing as strchr() but it starts from the end and works its way forward.
thanks again master 5001 i really appreciate your help guys.....umm master 5001 do you have some messengers account? cause i really need some expert on c to guide on learning and i respect your knowledge about in c programming...i you would like to share your messenger account you could pm it to me...or if you do not like it's fine to me....thanks again so much
Yeah its on my profile thingy. My msn is master5001 _at_ hotmail _dot_ com... I am only publicly posting it on the thread because of the fact that it used to be publicly viewable to anyone... I am not seeing it on my profile anymore, though it is listed on my user control panel. Whatever. My contact info is not top secret.
thanks again master5001..i appreciate it
The examples will loop forever unless you adjust the token pointer, because it will keep finding the same part of the string. As simple as t++; really.