1 / 12

STRINGS IN C

STRINGS IN C. Contents. STRINGS Memory Representation Declaring and Initializing string variables String functions Example: String is palindrome or not Result. STRINGS.

rchancellor
Download Presentation

STRINGS IN C

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. STRINGS IN C

  2. Contents • STRINGS • Memory Representation • Declaring and Initializing string variables • String functions • Example: String is palindrome or not • Result

  3. STRINGS A string is a collection of characters .The string in C programming language is actually a one-dimensional array of characters which is terminated by a null character '\0'. Example: char a[ ]={‘H’,‘E’,‘L’,‘L’,‘O’,‘\0’}; BACK

  4. Memory Representation of string In the memory character of array or string is: It is not necessary to write ‘\0’ when initializing strings.The C compiler automatically places the '\0' at the end of the string when it initializes the array. BACK

  5. Declaring and Initializing string variables Strings can be initialized as follows: char a[6]=“hello”; Or char a[6]={‘H’,‘E’,‘L’,‘L’,‘O’,‘\0’}; Strings can also be initialized without specifying the size: char a[ ]=“hello”; Or char a[ ]={‘H’,‘E’,‘L’,‘L’,‘O’,‘\0’}; BACK

  6. String functions C provide large number of library functions for manipulating strings. these are as follows: • Strlen( ) • Strlcat( ) • Strcpy( ) • Strcmp( ) • Strrev( ) • Strlwr( )

  7. Strlen( ):-This function calculate the length of the string . The syntax is: n=strlen (string); • Strcat( ):-This function appends one string at the end of the another string . The syntax is: strcat (str1,str2); • Strcpy( ):-This function copies a string to another string. The syntax is: strcpy(str1,”hello”);

  8. Strcmp( ):-This function compare two strings. The syntax is: strcmp (str1,str2); • Strrev( ):-This function reverse the string. The syntax is: strrev (Hello); • Strlwr( ):-This function calculate the length of the string.The syntax is: stlwr (str1);

  9. Strupr( ):-This function converts strings to upper string. The syntax is: strupr (str1); NOTE:-These are the standard library functions handled by string. BACK

  10. Example: String is palindrome or not #include<stdio.h> #include<conio.h> #include<string.h> void main() { char s1[20],s2[20]; int n; clrscr(); puts("enter a string..."); gets(s1); n=strlen(s1); printf(“length is=%d\n”,n); strcpy(s2,s1); strrev(s2); if(strcmp(s1,s2)==0) printf("string is palidrome"); else printf("string is not palidrome"); getch(); } BACK

  11. Result BACK

  12. THANKS BACK TO INDEX

More Related