Posts

Showing posts from March, 2024

String Functions in C Language(C Language)

  C String Functions There are many important string functions defined in "string.h" library. No. Function Description 1) strlen(string_name) returns the length of string name. 2) strcpy(destination, source) copies the contents of source string to destination string. 3) strcat(first_string, second_string) concats or joins first string with second string. The result of the string is stored in first string. 4) strcmp(first_string, second_string) compares the first string with second string. If both strings are same, it returns 0. 5) strrev(string) returns reverse string. 6) strlwr(string) returns string characters in lowercase. 7) strupr(string) returns string characters in uppercase. 8) strstr( st

C gets() and puts() functions (C language)

  C gets() and puts() functions The gets() and puts() are declared in the header file stdio.h. Both the functions are involved in the input/output operations of the strings. C gets() function The gets() function enables the user to enter some characters followed by the enter key. All the characters entered by the user get stored in a character array. The null character is added to the array to make it a string. The gets() allows the user to enter the space-separated strings. It returns the string entered by the user. Declaration char [] gets( char []);     Reading string using gets() #include<stdio.h>    void  main ()   {        char  s[30];       printf( "Enter the string? " );       gets(s);       printf( "You entered %s" ,s);   }   Output Enter the string? hi students You entered hi students C puts() function The puts() function is very much similar to printf() function. The puts() function is used to print the string o

Strings in C Language

  C Strings Ø   The string can be defined as the one-dimensional array of characters terminated by a null ('\0'). Ø   The character array or the string is used to manipulate text such as word or sentences. Ø   Each character in the array occupies one byte of memory, and the last character must always be 0. Ø   The termination character ('\0') is important in a string since it is the only way to identify where the string ends. Ø   When we define a string as char s[10], the character s[10] is implicitly initialized with the null in the memory. There are two ways to declare a string in c language. By char array By string literal Let's see the example of declaring  string by char array  in C language. 1.        char  ch[10]={ 'e' ,  'x' ,  'a' ,  'm' ,  'p' ,  'l' ,  'e' , '\0' };   As we know, array index starts from 0, so it will be represented as in the figure given bel