Skip to main content

Posts

Showing posts from January, 2023

Write a 'c' program to calculate the length of the string ?

    Calculate the length of the string strlen( ) :  This function will calculate the length of the  string.by length,we means the number of characters present in the string,excluding the NULL character. The general form is , int strlen(char [ ]) Consider the following , #include<stdio.h> #include<string.h> #include<conio.h> void main() { char s[50]; int len; clrscr( ); printf("\nEnter the String :"); scanf("%s",s); len=strlen(s); printf("\nLength=%d",len); getch( ); } output : Enter the string : ajay Length = 4 Join us on Facebook:  Click Here    

WAP read the multiple words string using the gets( ) function in C ?

  Gets() function The multiple words string using the gets( ) function  Because the scanf( ) function will get terminated by pressing the space. But if you want to read the multiple words string , we have to make use of the gets( ) function. gets( ) : This function is present in the header file stdio.h and  is used to read the string which can even contain the spaces. Thus, the gets( ) will get terminated only by pressing the enter. The general form is ,   gets(string name); Consider the following program, #include<stdio.h> #include<conio.h> void main( ) { char s[50]; clrscr( ); printf("\nEnter the string :"); gets(s); printf("\nYour string : %s",s); getch(); } output : Enter the string : computer science Your string : computer science In "C" programming language , we are provided with a separate file "string.h" which will be used for the string handling. It contains various pre-defined functions , which will used for ...