Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

String functions in C

2,589 views

Published on

String functions in C

  • Be the first to comment

String functions in C

  1. 1. String Functions in C Typing Speed: 25 Ismail Ismailpk456@gmail.com Ismail Ismu Ismail Ismu in.linkedin.com/in/profilena me 8086303494
  2. 2. String Function The standard library for C string functions is string.h. This header file defines tons of useful string manipulation functions including
  3. 3. String Functions  strcmp  strcat  strcpy  strlen
  4. 4. strcmp • Strcmp() in C programming language is used to compare two strings. If both the strings are equal then it gives the result as zero but if not then it gives the numeric difference between the first non matching characters in the strings.
  5. 5. strcat • The strcat() function is used for string concatenation in C programming language. It means it joins the two strings together
  6. 6. strcpy • strcpy function copies a string from a source location to a destination location and provides a null character to terminate the string.
  7. 7. strlen The strlen( ) function is used to calculate the length of the string. It means that it counts the total number of characters present in the string which includes alphabets, numbers, and all special characters including blank spaces.
  8. 8. Strcmp Syntax int strcmp ( const char * str1, const char * str2 ); Example int main() { char str1[30],str2[30]; printf("Enter first string: "); scanf("%s",&str1); printf("Enter second string: "); scanf("%s",&str2); if(strcmp(str1,str2)==0) printf("Both strings are equal"); else printf("Strings are unequal"); return 0; }
  9. 9. Strcat Syntax strcat(first_string,second_string); Example int main() { char str1[30]="www.cprogramming"; char str2[15]="expert.com"; printf("nn string 1 : %stt string 2 : %snn",str1,str2); printf("nn strcat(str1,str2) : %snn", strcat(str1,str2)); getch();
  10. 10. Strcpy Syntax strcpy(destination,source); Example int main() { char a[10],b[10]; printf("Enter string: "); scanf("%s",&a); strcpy(b,a); printf("Copied string: "); printf("%s",b); return 0; }
  11. 11. Strlen Syntax temp_variable = strlen(string_name); Example int main() { char a[20]; printf("Enter string: "); scanf("%s",&a); printf("Length of string =%d n",strlen(a)); }
  12. 12. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  13. 13. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550
  14. 14. THE END

×