0% found this document useful (0 votes)
26 views1 page

7 Sring Handling Function in c

Uploaded by

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

7 Sring Handling Function in c

Uploaded by

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

#include <stdio.

h>
#include <string.h>

int main() {
char str1[50], str2[50], str3[50];
int len, cmp_result;

strcpy(str1, "Hello, World!"); // Copying a string into str1


printf("str1 after strcpy: %s\n", str1);

len = strlen(str1); // Calculating length of str1


printf("Length of str1: %d\n", len);

strcpy(str2, " - C Programming");


strcat(str1, str2); // Concatenating str2 to str1
printf("str1 after strcat: %s\n", str1);

scmp_result = strcmp(str1, "Hello, World! - C Programming");


if (cmp_result == 0)
printf("str1 is equal to the comparison string.\n");
else if (cmp_result > 0)
printf("str1 is greater than the comparison string.\n");
else
printf("str1 is less than the comparison string.\n");

strncpy(str3, str1, 5); // Copying the first 5 characters of str1 into str3
str3[5] = '\0'; // Null-terminate str3
printf("str3 after strncpy: %s\n", str3);

strncat(str1, " - Demo", 5); // Append the first 5 characters of " - Demo" to
str1
printf("str1 after strncat: %s\n", str1);

char *ch_ptr = strchr(str1, 'C'); // Finding first occurrence of 'C'


if (ch_ptr != NULL)
printf("Character 'C' found in str1 at position: %ld\n", ch_ptr - str1);
else
printf("Character 'C' not found in str1.\n");

return 0;
}

You might also like