Length of String using Pointers coderinme

Length of String using Pointers coderinme

Length of String using Pointers coderinme
Before coding, we should know the difference between character and string.
A character is a single character. It might be the letter `A’, or the digit `2′, or the symbol `&’.
A string is a set of zero or more characters. For example, the string “and” consists of the characters `a’, `n’, and ‘d’. We know that we can easily find the length of a string using the  pointer ( total number of characters in a string) very quickly using the strlen() function. But now let’s do it without using this function. For this we need to use the concept of Pointers in C

#include<stdio.h>
int n_strlen(char * p)
{
int i = 0;
while( *p != '\0')
{
i++;
p++;
}
return i;
}
int main()
{
int len;
char a[100];
printf("Enter Your string: ");
gets(a);
len = n_strlen(a);
printf("Length of string: %d",len);
getch();
return 0;
}

C coder

Length of String using Pointers coderinme
All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.