Header file:
string.h
Synopsis:
size_t strcspn(char *str, char *rej);
Description:
It returns the length of the prefix in string str which consists of characters not in string rej.
strcspn function C example:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main() {
char input[100];
int size;
printf("Enter your input:");
fgets(input, 50, stdin);
size = strcspn(input, "abcdefghijklmnopqrstuvwxyz");
printf("Output: %d\n", size);
return 0;
}
#include<stdlib.h>
#include<string.h>
int main() {
char input[100];
int size;
printf("Enter your input:");
fgets(input, 50, stdin);
size = strcspn(input, "abcdefghijklmnopqrstuvwxyz");
printf("Output: %d\n", size);
return 0;
}
Output:
jp@jp-VirtualBox:~/$ ./a.out
Enter your input:12345helloworld
Output: 5
Enter your input:12345helloworld
Output: 5
Here, the input string is "12345helloworld" and the other string rej is "abcdefghijklmnopqrstuvwxyz". Characters in the prefix ("12345")of input string is not available in the string rej. So, the length of "12345" is returned as return value.
nice article for beginners.thank you.
ReplyDeletejava basic operator
java basic operator