#include #include int main(void) { char s0[] = "abcdefghijklmnopqrstuvwxyz"; char s1[30] = "string 1"; char s2[] = "another string"; int l1, l2; printf("S0: %s\nS1: %s\nS2: %s\n", s0, s1, s2); printf("\n-----\nPrint the length of the string\n"); //Print the length of the string printf("Length - s1: %d s2: %d\n", l1 = strlen(s1), l2 = strlen(s2)); printf("\n-----\nConcatenate two strings and print the result\n"); //Concatenate two strings and print the result printf("Concatenated: %s\n", strcat(s1,s2)); printf("\n-----\nCompare two strings and copy the lesser to the greater\n"); //Compare two strings and copy the lesser to the greater printf("S0: %s\nS1: %s\nS2: %s\n", s0, s1, s2); if (strcmp(s1, s2) < 0) { printf("s1 less than s2\n"); strcpy(s2, s1); } else if (strcmp(s1,s2) > 0) { printf("s2 less than s1\n"); strcpy(s1, s2); } printf("S0: %s\nS1: %s\nS2: %s\n", s0, s1, s2); printf("\n-----\nCount the occurrences of '?'\n"); //Find how many times the character '?' occurs in a string char s3[] = "a.b?c.d?e."; char *p = strchr(s3, '?'); int count = 0; while (p != NULL) { count++; p = strchr(p + 1, '?'); } printf("Count: %d\n", count); printf("\n-----\nFind the tokens in the string\n"); //Find the tokens in a string, print one by one char s4[] = "there are seven tokens in this string"; char *pt = strtok(s4, " "); while (pt != NULL) { printf("%s\n", pt); pt = strtok(NULL, " "); } return 0; }