Created
February 23, 2018 13:17
-
-
Save jq2/8b9d0f54fec04ffff37ab7f8ff7af919 to your computer and use it in GitHub Desktop.
Contar elementos/items em um array de ponteiros do tipo char.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int my_strlen(const char *str); | |
int main(int argc, char* argv[]) | |
{ | |
char *teste[10][10] = { | |
{"teste"}, | |
{"b"}, | |
{"c"}, | |
}; | |
char *teste_a[] = {"a", "b", "c", "def"}; | |
printf("Total of elements: %d\n", my_strlen(teste[0][0])); | |
printf("Total of teste_a: %ld\n", sizeof(teste_a) / sizeof(teste_a[0])); | |
return 1; | |
} | |
int my_strlen (const char *str) { | |
int iter = 0; | |
const char *p = str; | |
while(*p) { | |
printf("char: %c\n", *p); | |
iter++; | |
p++; | |
} | |
return iter; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment