#include <stdio.h>
int MyStrlen(const char *si);
int main() {
char str[] = "a";
char str1[] = "HELLO";
char str2[] = "";
printf("Length: %d \n", MyStrlen(str));
printf("Length: %d \n", MyStrlen(str1));
printf("Length: %d \n", MyStrlen(str2));
return 0;
}
int MyStrlen(const char *si) {
int input;
for(input = 0; *si; si++)
input++;
return input;
}
potato4610
0
Newbie Poster
Recommended Answers
Jump to PostWhat have you tried to solve this problem?
Jump to PostI have some idea's for fixing it, but that's NOT the code that you posted!
I can't fix code that I can't see -- trust me on this.;)
Post the code that you tried, and got this error on, and tell me what compiler you're using, and the …
Jump to Post<moderator, please delete>
Jump to PostYou were posting your updated code, at the same time I was writing my post - and looking at your first post, only. I was also looking into my header files on "size_t", which is why my post was so much later than yours (although the post was started before …
Jump to PostTo be consistent, I would:
1) remove the cast to int, in the printf() statements
2) change int input to size_t input, in the MyStrLen() functionand
3) use %u for the format identifier in the printf() statements.
That works for me, with no errors or …
All 24 Replies
Adak
419
Nearly a Posting Virtuoso
potato4610
0
Newbie Poster
potato4610
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
Adak
419
Nearly a Posting Virtuoso
potato4610
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
Adak
419
Nearly a Posting Virtuoso
potato4610
0
Newbie Poster
potato4610
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
potato4610
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
potato4610
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
potato4610
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
Adak
419
Nearly a Posting Virtuoso
potato4610
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
potato4610
0
Newbie Poster
Adak
419
Nearly a Posting Virtuoso
potato4610
0
Newbie Poster
potato4610
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.