Computer Science & C Programming


C Programming

The next step when learning a programming language is to learn standard libraries such as GLib or Gtk for instance.

// Usage: gcc sample.c -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0 -o sample.exe && ./sample.exe

#include <glib.h>

void main() {
  g_print("Welcome to you");

  GList* list = NULL;
  list = g_list_append(list,"Welcome");
  list = g_list_append(list,"to");
  list = g_list_append(list,"you");

  for (GList* it=list; it!=NULL; it=it->next)
    g_print("%s ",it->data);

  if (g_list_index(list,"to")!=-1) 
    g_print("Found at pos %i",g_list_index(list,"to"));
  else g_print("Not found");
}

NB. It must be required to install libglib2.0-dev (with sudo apt install -y).