

Creating an \hyperlink{group__Eina__List__Group_ga3295e1210efea1fb0fd6acbf3cbc1f29}{Eina\+\_\+\+List} and adding elements to it is very easy and can be understood from an example\+: First thing is always to include \hyperlink{Eina_8h}{Eina.\+h}, for this example we also include stdio.\+h so we can use printf. 
\begin{DoxyCodeInclude}
\textcolor{preprocessor}{#include <stdio.h>}
\textcolor{preprocessor}{#include <\hyperlink{Eina_8h}{Eina.h}>}

\end{DoxyCodeInclude}


Just some boilerplate code, declaring some variable and initializing eina. 
\begin{DoxyCodeInclude}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   (void)argc;
   (void)argv;
   \hyperlink{struct__Eina__List}{Eina\_List} *list = NULL;
   \hyperlink{struct__Eina__List}{Eina\_List} *l;
   \textcolor{keywordtype}{void} *list\_data;

   \hyperlink{group__Eina__Main__Group_gabf448ada5bc81a07342b66c6f818ee5e}{eina\_init}();

\end{DoxyCodeInclude}
 Here we add a sequence of elements to our list. By using append we add elements to the end of the list, so the list will look like this\+:~\newline
  
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{eina_list_example_01_a}}
\end{DoxyImageNoCaption}
 
\begin{DoxyCodeInclude}

   list = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(list, \textcolor{stringliteral}{"tigh"});
   list = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(list, \textcolor{stringliteral}{"adar"});
   list = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(list, \textcolor{stringliteral}{"baltar"});
   list = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(list, \textcolor{stringliteral}{"roslin"});

\end{DoxyCodeInclude}
 There are a couple of interesting things happening here, first is that we are passing a N\+U\+LL pointer to the first \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\+\_\+list\+\_\+append()} call, when this is done a list is created. The other {\bfseries very} important detail to notice is that the return value is attributed to the {\itshape list} variable, this needs to be done every time we use a a function that alters the contents of the list.

Now that we have a list with some elements in it we can look at its contents. 
\begin{DoxyCodeInclude}

   \hyperlink{group__Eina__List__Group_gad02f746a08ee0b12b7ed66d4bc0d71d8}{EINA\_LIST\_FOREACH}(list, l, list\_data)
     printf(\textcolor{stringliteral}{"%s\(\backslash\)n"}, (\textcolor{keywordtype}{char}*)list\_data);

\end{DoxyCodeInclude}


There are many ways of accessing elements in the list, including by its index\+: 
\begin{DoxyCodeInclude}
   printf(\textcolor{stringliteral}{"\(\backslash\)n"});

   l = \hyperlink{group__Eina__List__Group_gad4a1e3b0fdecd8ed4cb2ff592ceeb553}{eina\_list\_nth\_list}(list, 1);

\end{DoxyCodeInclude}
 \begin{DoxyNote}{Note}
It should be noted that the index starts at 0.
\end{DoxyNote}
\hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\+\_\+list\+\_\+append()} is not the only way to add elements to a a list. A common requirement is to add an element in a specific position this can be accomplished using \hyperlink{group__Eina__List__Group_ga4676c189ca4bcfa22d7ecfbcd00200ae}{eina\+\_\+list\+\_\+append\+\_\+relative()} and \hyperlink{group__Eina__List__Group_gafa705d4483487e53d1be93a30e43c66d}{eina\+\_\+list\+\_\+append\+\_\+relative\+\_\+list()}\+: 
\begin{DoxyCodeInclude}
   list = \hyperlink{group__Eina__List__Group_gafa705d4483487e53d1be93a30e43c66d}{eina\_list\_append\_relative\_list}(list, \textcolor{stringliteral}{"cain"}, l);

   list = \hyperlink{group__Eina__List__Group_ga4676c189ca4bcfa22d7ecfbcd00200ae}{eina\_list\_append\_relative}(list, \textcolor{stringliteral}{"zarek"}, \textcolor{stringliteral}{"cain"});

\end{DoxyCodeInclude}
 First {\itshape \char`\"{}cain\char`\"{}} is added after the second element(remember that indexes are 0 based) and then we add {\itshape \char`\"{}zarek\char`\"{}} after {\itshape \char`\"{}cain\char`\"{}}.

\hyperlink{group__Eina__List__Group_ga3295e1210efea1fb0fd6acbf3cbc1f29}{Eina\+\_\+\+List} also has prepend analogs to append functions we have used so far\+: 
\begin{DoxyCodeInclude}

   list = \hyperlink{group__Eina__List__Group_ga9f35bfc7c5b798014c3e0a74bc6f39ad}{eina\_list\_prepend}(list, \textcolor{stringliteral}{"adama"});

   list = \hyperlink{group__Eina__List__Group_gad44370d18554ff250d2e9ddac4653caf}{eina\_list\_prepend\_relative}(list, \textcolor{stringliteral}{"gaeta"}, \textcolor{stringliteral}{"cain"});

   list = \hyperlink{group__Eina__List__Group_ga03a77b1579ee83bcab4bc3d67375d4b1}{eina\_list\_prepend\_relative\_list}(list, \textcolor{stringliteral}{"lampkin"}, l);

\end{DoxyCodeInclude}
 With this additions our list now looks like this\+:~\newline
  
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{eina_list_example_01_b}}
\end{DoxyImageNoCaption}


Once done using the list it needs to be freed, and since we are done with eina that also need to be shutdown\+: 
\begin{DoxyCodeInclude}

   \hyperlink{group__Eina__List__Group_gad02f746a08ee0b12b7ed66d4bc0d71d8}{EINA\_LIST\_FOREACH}(list, l, list\_data)
     printf(\textcolor{stringliteral}{"%s\(\backslash\)n"}, (\textcolor{keywordtype}{char}*)list\_data);

   \hyperlink{group__Eina__List__Group_ga608bd2fbf06293a1b794648990703ab4}{eina\_list\_free}(list);

   \hyperlink{group__Eina__Main__Group_ga6741fcaba116e31e96ce14dcfa03f568}{eina\_shutdown}();

   \textcolor{keywordflow}{return} 0;
\}

\end{DoxyCodeInclude}


The full source code can be found on the examples folder on the \hyperlink{eina_list_01_c}{eina\+\_\+list\+\_\+01.c} file. 