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");
Printable View
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
What does your manual say?Quote:
Originally Posted by paperbox005
http://www.neosoft.com/neosoft/man/strpbrk.3.html
Quote:
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.
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.Quote:
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.Quote:
but how do i do a string compare with a pointer and a character?>
if( *ptr == '%' )
Good! If you have more choices, also consider switch-case.Quote:
Originally Posted by paperbox005