Breaking

Implementation without using standard library functions[BCA-II]

Implementation without using standard library functions

 find the length of the string using given library function, but in this program, we are finding the length of the string without using library function

#include<stdio.h>
 int main() 
{   
char str[100]; 
  int length;  
  printf("\nEnter the String : ");  
gets(str);    length = 0;  // Initial Length    
while (str[length] != '\0')      
length++;    printf("\nLength of the String is : %d", length);
   return(0);
}
Explanation of Program :

printf("\nEnter the String : ");gets(str);

After that we have initialized the length variable with zero. “length” variable is used to keep track of the number of character accessed

length = 0;  // Initial Length
The initial length is 0. Now we are accessing very first character. If it is equal to NULL then we are terminating the loop else we are incrementing the length.

while (str[length] != '\0')      length++;


कोई टिप्पणी नहीं:

एक टिप्पणी भेजें