0% found this document useful (0 votes)
17 views3 pages

p17 (String Processing)

Uploaded by

abaiju696
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

p17 (String Processing)

Uploaded by

abaiju696
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

/* 17. Given S1={“Flowers”} ; S2={“are beautiful”} I. Find the length of S1 II.

Concatenate S1 and S2
III. Extract the substring “low” from S1 IV. Find “are” in S2 and replace it with “is”*/

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

int main() {

char S1[] = "Flowers";

char S2[] = "are beautiful";

int choice;

while(1)

printf("1. Find the length of S1\n");

printf("2. Concatenate S1 and S2\n");

printf("3. Extract the substring 'low' from S1\n");

printf("4. Find 'are' in S2 and replace it with 'is'\n");

printf("5.exit\n");

printf("Enter your choice:\n");

scanf("%d", &choice);

switch (choice) {

case 1:

printf("Length of S1: %zu\n", strlen(S1));

break;

case 2: {

char result[100];

strcpy(result, S1);

strcat(result, " ");

strcat(result, S2);

printf("Concatenated string: %s\n", result);

break;
}

case 3: {

char substring[4];

strncpy(substring, S1 + 1, 3);

substring[3] = '\0';

printf("Extracted substring from S1: %s\n", substring);

break;

case 4: {

char *found = strstr(S2, "are");

if (found != NULL) {

strncpy(found, "is ", 3);

printf("Modified S2: %s\n", S2);

} else {

printf("'are' not found in S2\n");

break;

case 5:

exit(0);

default:

printf("Invalid choice\n");

break;

return 0;

}
OUTPUT

You might also like