0% found this document useful (0 votes)
3 views2 pages

string code

The document contains four C programs demonstrating various string manipulation functions. Program 1 showcases string copying, concatenation, and length calculation; Program 2 illustrates substring searching; Program 3 reverses a string; and Program 4 compares strings for equality. Each program includes relevant header files and prints the results of the operations performed.

Uploaded by

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

string code

The document contains four C programs demonstrating various string manipulation functions. Program 1 showcases string copying, concatenation, and length calculation; Program 2 illustrates substring searching; Program 3 reverses a string; and Program 4 compares strings for equality. Each program includes relevant header files and prints the results of the operations performed.

Uploaded by

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

Program 1

#include <stdio.h>
#include <string.h>
int main () {
char str1[12] = "Hello";
char str2[12] = "World";
char str3[12];
int len ;
/* copy str1 into str3 */
strcpy(str3, str1);
printf("strcpy( str3, str1) : %s\n", str3 );
/* concatenates str1 and str2 */
strcat( str1, str2);
printf("strcat( str1, str2): %s\n", str1 );
/* total lenghth of str1 after concatenation */
len = strlen(str1);
printf("strlen(str1) : %d\n", len );
return 0;
}

Program 2
Strstr():-
#include <stdio.h>
#include <string.h>
int main()
{
const char haystack[20] = "mescoepune.org";
const char needle[10] = "org";
char *ret;
ret = strstr(haystack, needle);
printf("The substring is: %s\n", ret);
return(0);
}

Program 3
#include<stdio.h>
#include<string.h>
int main()
{
int l,i;char ch;
char s1[10]="jayanti";
l=strlen(s1);
for(i=0;i<l/2;i++)
{
ch=s1[i];
s1[i]=s1[l-1-i];
s1[l-1-i]=ch;
}
printf("%s",s1);
}

Program 4- Equality
#include <stdio.h>
#include <string.h>
int main()
{
char str1[] = "cummins", str2[] = "CuMiNs", str3[] =
"CUMMINS", str4[] = "cummins";
int result;
result = strcmp(str1, str4);
printf("strcmp(str1, str4) = %d\n", result);
return 0;
}

You might also like