if i have
Code:char * ptr = NULL; ptr= strpbrk(str, "-%"); /* how do i write an if statement checking if ptr found a - or a % and is pointing to it?*/ if(ptr == '%') printf("this isnt working.. could someone help me?\n");
if i have
Code:char * ptr = NULL; ptr= strpbrk(str, "-%"); /* how do i write an if statement checking if ptr found a - or a % and is pointing to it?*/ if(ptr == '%') printf("this isnt working.. could someone help me?\n");
First you need
if ( ptr != NULL )
Then you can look at *ptr to find which char it is pointing to
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.
What does your manual say?Originally Posted by paperbox005
http://www.neosoft.com/neosoft/man/strpbrk.3.html
The strpbrk() function locates in the null-terminated string s the first occurrence of any character in the string charset and returns a pointer to this character. If no characters from charset occur anywhere in s strpbrk() returns NULL.
Emmanuel Delahaye
"C is a sharp tool"
yes i know it returns a pointer, but how do i do a string compare with a pointer and a character?>
Actually, it returns an address that it is useful to store in a pointer of type char.Originally Posted by paperbox005
Why a string compare? You want a character compare. Use '*' to dereference the pointer and '==' to compare. Nothing really new here... Do your best. I want to see your code.but how do i do a string compare with a pointer and a character?>
Emmanuel Delahaye
"C is a sharp tool"
if( *ptr == '%' )
Good! If you have more choices, also consider switch-case.Originally Posted by paperbox005
Emmanuel Delahaye
"C is a sharp tool"