Answer to Question #202311 in C for Prasanna

Question #202311

write the function to find of the string which is passed from main program using pointers


Runtime Input :

hello


Output :

5


1
Expert's answer
2021-06-02T16:19:02-0400
#include <stdio.h>


int lengthOfString(char* string)
{
    int length = 0;
    while(*string!='\0')
    {
        length++;
        string++;
    }
    return length;
}


int main()
{
    char* hello = "hello";
    printf("Input: %s\n",hello);
    int length = lengthOfString(hello);
    printf("Output: %d", length);


    printf("\n\n");
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS