Ejemplo n.º 1
0
int create_client(const char *hostname, const int hostport) {
    int descript;
    socket_address hostaddr;
    int adlen;

    /* winlocal
    if ((descript=socket(PF_INET, SOCK_STREAM, 0)) < 0)
    */
    if ((descript=socket(PF_INET, SOCK_STREAM, 0)) == -1)		// winlocal
        fatal("socket");

    name_to_number(AF_INET, hostname, hostport, &hostaddr, &adlen);

    if (connect(descript, &hostaddr.inet, adlen) < 0)
        fatal("connect");

    return(descript);
}
Ejemplo n.º 2
0
t_graphe	*parcours_profondeur(t_graphe* graphe, char *n_s)
{
  int			*visite;
  int			*names;
  t_pile		*pile;
  int			s;
  int			u;
  int			v;
  int			i;
  int			succ;
  int			size;
  t_ch_int		*tmp;
  t_ch_ch_int		*ttmp;
  t_graphe		*T;
  void			*data;

  u = 0;
  v = 0;
  data = 0;
  succ = 0;
  size = taille(graphe);
  visite = xmalloc(sizeof(*visite)*size);
  names = xmalloc(sizeof(*names)*size);
  pile = xmalloc(sizeof(*pile));
  pile->pile = xmalloc(sizeof(*pile->pile)*size);
  pile->taille_pile = 0;
  T = init(GO);
  empiler(name_to_number(graphe, n_s), pile);
  for (i = 0, ttmp = graphe->graphe; i < size; i++, ttmp = ttmp->next)
    names[i] = ttmp->number;
  inserer(get_index(s, names, size), visite);
  while (pile->taille_pile != 0)
    {
      u = sommet(pile);
      succ = 0;
      for (ttmp = graphe->graphe; ttmp != NULL; ttmp = ttmp->next)
	if (ttmp->number == u)
	  break;
      for (tmp = ttmp->liste; tmp != NULL; tmp = tmp->next)
	if (!visite[get_index(tmp->number, names, size)])
	  succ++;
      if (succ != 0)
	{
	  for (ttmp = graphe->graphe; ttmp != NULL; ttmp = ttmp->next)
	    if (ttmp->number == u)
	      break;
	  for (tmp = ttmp->liste; tmp != NULL; tmp = tmp->next)
	    if (!visite[get_index(tmp->number, names, size)])
	      {
		v = tmp->number;
		data = tmp->data;
		break;
	      }
	  ajouterArc(T, number_to_name(graphe, u), number_to_name(graphe, v), data);
	  empiler(v,pile);
	  inserer(get_index(v, names, size), visite);
	}
      else
	depiler(pile);
    }
  return (T);
}
Ejemplo n.º 3
0
#include<stdio.h>
int main()
{
	int name_to_number(str name)
	{
		    if(name=="rock")
            {
            return rock=0;
           }
		   else{
		   	if(name=="spock")
		   	{
		   		return spock=1;
		   	}
		   	} 
		}
	}

printf("%d",name_to_number("rock"));
return 0;
}