Skip to content

Instantly share code, notes, and snippets.

@jq2
Created February 23, 2018 13:17
Show Gist options
  • Save jq2/8b9d0f54fec04ffff37ab7f8ff7af919 to your computer and use it in GitHub Desktop.
Save jq2/8b9d0f54fec04ffff37ab7f8ff7af919 to your computer and use it in GitHub Desktop.
Contar elementos/items em um array de ponteiros do tipo char.
#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