String Functions
String Functions
Strlen()
strcat(dest, src);
printf("Final destination string : |%s|", dest);
Examples:
1. #include <stdio.h>
return(0);
}
#include <string.h>
int main ()
{
2. #include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[])
char str[50];
int len;
char example[100];
len = strlen(str);
Strcat()
Strcpy()
1. #include <stdio.h>
#include <string.h>
int main ()
strcpy(dest, src);
char src[50], dest[50];
return(0);
char arr[100];
gets(arr);
#include <string.h>
strrev(arr);
return 0;
Strncat()
Examples:
printf("%s\n", example);
return 0;
}
Strrev()
1. #include <stdio.h>
#include <string.h>
int main ()
{
char src[50], dest[50];
Examples:
1. #include <stdio.h>
#include <string.h>
return(0);
}
main()
{
2. #include <stdio.h>
int main()
char s1[20];
char string1[20];
gets(s1);
char string2[20];
strrev(s1);
strcpy(string1, "Hello");
strcpy(string2, "Hellooo");
getch();
}
2. #include <stdio.h>
return 0;
#include <string.h>
int main()
{
Strncpy()
printf("%s\n", example);
return 0;
}
1. #include <stdio.h>
#include <string.h>
int main()
{
char src[40];
char dest[12];
memset(dest, '\0', sizeof(dest));
strcpy(src, "This is tutorialspoint.com");
strncpy(dest, src, 10);
printf("Final copied string : %s\n", dest);
Strcmp()
return(0);
char str2[15];
int ret;
2. #include <stdio.h>
strcpy(str1, "abcdef");
#include <string.h>
strcpy(str2, "ABCDEF");
ret = strcmp(str1, str2);
if(ret < 0)
char example[50];
}
else
{
printf("str1 is equal to str2");
return(0);
}
2. #include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[])
{
int result;
char example1[50];
char example2[50];
strcpy(example1, "C programming at
TechOnTheNet.com");
strcpy(example2, "C programming is fun");
strcpy(string2, "Hellooo");
printf("Return Value is : %d\n", strncmp( string1,
string2, 20));
return 0;
}
2. #include <stdio.h>
#include <string.h>
int main ()
{
char str1[15];
char str2[15];
int ret;
strcpy(str1, "abcdef");
strcpy(str2, "ABCDEF");
return 0;
Strncmp
if(ret < 0)
Examples:
1. #include <stdio.h>
int main() {
char string1[20];
char string2[20];
else
strcpy(string1, "Hello");
{
printf("str1 is equal to str2");
strcpy(string2, "Hellooo");
}
return(0);
}
Strincmp()
Format:
Use:
Examples: