I have been working on my C assignment where I try to replicate strlen() function without actually using it. This is the code I have been trying to get working. However, somehow the main function does not reflect what's happenning in mystrlen() function. Can you please tell me why it does not work as the strlen() function?
#include <stdio.h>
int mystrlen(char *input_string) {
/* This function returns the length of the input string */
/* WRITE FUNCTION CODE HERE! */
char str1[50];
int abcd = 0;
scanf("%s", str1);
int m;
for(m=0; str1[m]; m++){
abcd ++;
}
return 0;
}
int main(int argc, char **argv) {
int length;
if (argc!=2) {
printf("Usage: strlen <input_string_with_no_space_inside_it>\n\n");
return 1;
}
length = mystrlen(argv[1]);
printf("The length is: %d characters.\n",length);
return 0;
}