My task is: Write a program that calculates the length of a string without using the library
This is my answer, but there is a problem with execution. The length doesnt show properly ! the execution shows length as 107 or 127 for any string I insert.
#include <stdio.h>
#include <stdlib.h>
int main()
{
//Declaration of variables :
char ch[50+1];
int length, i;
//data :
printf("ch : ");
scanf("%s", &ch);
printf("\n");
//Search length of string :
i = 0;
do
{
if(ch[i] == '\0')
{
length = i;
}
else
{
i++;
}
}
while(ch[i] != '\0');
//Result "
printf("length pf %s is : %d \n", ch, length);
return 0;
} ```