FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
459 views
in Tutorial & Interview questions by Goeduhub's Expert (9.3k points)

 strspn and strcspn

1 Answer

0 like 0 dislike
by Goeduhub's Expert (9.3k points)
 
Best answer
Given a string, strspn calculates the length of the initial substring (span) consisting solely of a specific list of characters. strcspn is similar, except it calculates the length of the initial substring consisting of any characters except those listed:

/*  Provided a string of "tokens" delimited by "separators", print the tokens along  with the token separators that get skipped. */

#include <stdio.h>

#include <string.h>

int main(void)

{    

const char sepchars[] = ",.;!?";    

char foo[] = ";ball call,.fall gall hall!?.,";    

char *s;    

int n;

for (s = foo; *s != 0; /*empty*/)

{                   /* Get the number of token separator characters. */        

n = (int)strspn(s, sepchars);

if (n > 0)            

printf("skipping separators: << %.*s >> (length=%d)\n", n, s, n);

        /* Actually skip the separators now. */        

s += n;

        /* Get the number of token (non-separator) characters. */        

n = (int)strcspn(s, sepchars);

if (n > 0)            

printf("token found: << %.*s >> (length=%d)\n", n, s, n);

        /* Skip the token now. */        

s += n;    

}

printf("== token list exhausted ==\n");

return 0;

}

Analogous functions using wide-character strings are wcsspn and wcscspn; they're used the same way.

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...