File: Stare vježbe/vjezbe09/56__strlen.c
/* 56__strlen.c Primjeri implementacije funkcije strlen. ----- Prototip: int strlen(char* s); Funkcija strlen vraca duljinu stringa s (ne ukljucujuci posljednji '\0' karakter). */ #include <stdio.h> #define MAX 50 int strlen1(char* s) { int i; for(i=0; s[i]!='\0'; i++); return i; } int strlen2(char* s) { char* p; for(p=s; *p; ++p); return p-s; } int strlen3(char* s) { char* p=s; while(*p) p++; return p-s; } int main() { char s1[MAX]; gets(s1); printf("strlen1(s1): %d\n", strlen1 (s1 )); printf("strlen2(s1): %d\n", strlen2 (s1 )); printf("strlen3(s1): %d\n", strlen3 (s1 )); return 0; }
|