aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/examples/eina_array_02.c
blob: e8973214f4ac004d1319c62f8d71905923143364 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//Compile with:
//gcc -g `pkg-config --cflags --libs eina` eina_array_02.c -o eina_array_02

#include <stdio.h>
#include <string.h>

#include <Eina.h>

Eina_Bool keep(void *data, void *gdata)
{
   if (strlen((const char*)data) <= 5)
      return EINA_TRUE;
   return EINA_FALSE;
}

int
main(int argc, char **argv)
{
   const char* strs[] = {
      "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
      "ten", "eleven", "twelve", "thirteen", "fourtenn", "fifteen", "sixteen",
      "seventeen", "eighteen", "nineteen", "twenty"
   };
   const char* strings[] = {
      "helo", "hera", "starbuck", "kat", "boomer",
      "hotdog", "longshot", "jammer", "crashdown", "hardball",
      "duck", "racetrack", "apolo", "husker", "freaker",
      "skulls", "bulldog", "flat top", "hammerhead", "gonzo"
   };
   Eina_Array *array;
   Eina_Array_Iterator iterator;
   const char *item;
   unsigned int i;

   eina_init();

   array = eina_array_new(10);

   for (i = 0; i < 20; i++)
     eina_array_push(array, strs[i]);

   eina_array_clean(array);
   for (i = 0; i < 20; i++)
     eina_array_push(array, strings[i]);

   eina_array_data_set(array, 17, "flattop");

   eina_array_remove(array, keep, NULL);
   EINA_ARRAY_ITER_NEXT(array, i, item, iterator)
     printf("item #%d: %s\n", i, item);

   eina_array_free(array);

   eina_shutdown();

   return 0;
}