string code
string code
#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;
}