Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C function string length that takes as input a string and returns as out

ID: 3628100 • Letter: W

Question

Write a C function
string length that takes as input a string and returns as output the number of characters
in the string. The input parameter must be of type char*, and you may assume that the
string is terminated by the null character.
Place your string length in a C le that includes a main method containing at least ve
tests of the function. For example, the call string length("hello world") should return
11, and the call string length("5") should return 1. (Of course, you should think of ve
additional tests.)

Explanation / Answer

// working fine ....use proper compiler.

// this is perfect code boss !!

#include<stdio.h>

#include<conio.h>

int string_length(char *s)

{

int n=0;

while(*s++)

n++;

return n;

}

int main()

{

char *s = "Hellow world";

printf("%d" ,string_length(s));

printf("%d" ,string_length("s"));

printf("%d" ,string_length("12"));

printf("%d" ,string_length("54322"));

getch();

return 0;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote