A
amanayin
size_t strcspn(char *str1, char *str2);
char *strpbrk(char *str, char *accept);
In the book i am using it says:
The function strpbrk() returns a pointer to the first
character in str that matches any of the characters in accept.
If it doesn't find a match, the function retuns NULL. As
previously explained for the function strchr(), you can
obtain the offset of the first match in str by subtracting
the pointer str from the pointer returned by strpbrk()
(if it isn't NULL, of cource).
For example, replace strcspn() on line 21 with strpbrk();
But when i do i get the following error
strcspn.c:21: warnig: assignment makes integer
from pointer without a cast
does this error have something to do with the functions
or have i missinterprtated what is said above could
some one please explain. And how do you use strpbrk()
properly
/* STRCSPN.C DEMONSTRATES THE STRSCPN() FUNCTION */
#include<stdio.h>
#include<string.h>
int main(void)
{
char buf1[80], buf2[80];
size_t loc;
/* INPUT THE STRINGS. */
printf("Enter the string to be searched: ");
fgets(buf1,80,stdin);
printf("Enter the string containing target characters: ");
fgets(buf2,80,stdin);
buf2[strlen(buf2)-1] = 0;
/* PERFORM THE SEARCH */
loc = strcspn(buf1, buf2);
if(loc == strlen(buf1))
printf("No match found\n");
else
printf("The first match was found at position %d.\n",loc);
return 0;
}
char *strpbrk(char *str, char *accept);
In the book i am using it says:
The function strpbrk() returns a pointer to the first
character in str that matches any of the characters in accept.
If it doesn't find a match, the function retuns NULL. As
previously explained for the function strchr(), you can
obtain the offset of the first match in str by subtracting
the pointer str from the pointer returned by strpbrk()
(if it isn't NULL, of cource).
For example, replace strcspn() on line 21 with strpbrk();
But when i do i get the following error
strcspn.c:21: warnig: assignment makes integer
from pointer without a cast
does this error have something to do with the functions
or have i missinterprtated what is said above could
some one please explain. And how do you use strpbrk()
properly
/* STRCSPN.C DEMONSTRATES THE STRSCPN() FUNCTION */
#include<stdio.h>
#include<string.h>
int main(void)
{
char buf1[80], buf2[80];
size_t loc;
/* INPUT THE STRINGS. */
printf("Enter the string to be searched: ");
fgets(buf1,80,stdin);
printf("Enter the string containing target characters: ");
fgets(buf2,80,stdin);
buf2[strlen(buf2)-1] = 0;
/* PERFORM THE SEARCH */
loc = strcspn(buf1, buf2);
if(loc == strlen(buf1))
printf("No match found\n");
else
printf("The first match was found at position %d.\n",loc);
return 0;
}