Exemple #1
0
char			*ft_itoa_base_ll(long long nbr, int base)
{
	char		*retour;
	int			nb;
	int			i;
	char		tab[17];

	if (nbr == 0)
		return (ft_alloc_str("0"));
	if (nbr < -9223372036854775807)
		return (ft_alloc_str("-9223372036854775808"));
	ft_strcpy(tab, "0123456789abcdef");
	i = nbr < 0 ? 1 : 0;
	nbr = nbr < 0 ? nbr * -1 : nbr;
	nb = compte(nbr, base);
	nb += i;
	retour = malloc(nb + 1);
	retour[0] = (i == 1 ? '-' : retour[0]);
	i = 1;
	while (nbr != 0)
	{
		retour[nb - i] = tab[nbr % base];
		nbr /= base;
		i++;
	}
	retour[nb] = '\0';
	return (retour);
}
Exemple #2
0
char            *ft_itoa_ptr(void *ptr)
{
	char		*retour;
	int		nb;
	int		i;
	char		tab[17];
	unsigned long	nbr;

	nbr = (unsigned long)ptr;
	if (nbr == 0)
		return (ft_alloc_str("0x0"));
	ft_strcpy(tab, "0123456789abcdef");
	nb = compte(nbr);
	retour = malloc(nb + 1 + 2);
	ft_strcpy(retour, "0x");
	i = 1;
	while (nbr != 0)
	{
		retour[nb - i + 2] = tab[nbr % 16];
		nbr /= 16;
		i++;
	}
	retour[nb + 2] = '\0';
	return (retour);
}
Exemple #3
0
int test(int c)
{
	switch(jeu[c])
	{
		case -1:
		case 10:
		case 11:
					/* on ne peut tester la l‚galit‚ */
					return 0;
		case 9:
					/* la l‚galit‚ est test‚e en v‚rifiant qu'aucune
					    des cases autour ne contient de 0 */
/*
		SI C'EST LE CAS IL S'AGIT D'UN BUG !!!!
*/
					if (jeu[c-TAILLEX-2] == 0) return 1;
					if (jeu[c-TAILLEX-1] == 0) return 1;
					if (jeu[c-TAILLEX] == 0) return 1;
					if (jeu[c-1] == 0) return 1;
					if (jeu[c+1] == 0) return 1;
					if (jeu[c+TAILLEX] == 0) return 1;
					if (jeu[c+TAILLEX+1] == 0) return 1;
					if (jeu[c+TAILLEX+2] == 0) return 1;
					return 0;
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
		case 8:
					/* la l‚galit‚ est test‚e en comptant le nombre
					    de bombes autour de la case */
					nbbombes = 0;
					nblibres = 0;
					compte(c-TAILLEX-2);
					compte(c-TAILLEX-1);
					compte(c-TAILLEX);
					compte(c-1);
					compte(c+1);
					compte(c+TAILLEX);
					compte(c+TAILLEX+1);
					compte(c+TAILLEX+2);

					if (nbbombes > jeu[c]) return 1;
					if (nblibres+nbbombes == 8)
					{
						if (nbbombes!=jeu[c]) return 1;
					}
					return 0;
		default:
					printf("C'est quoi cette fausse valeur ???\n");
					return 55;
	}
}
Exemple #4
0
main(){
  char chaine[] = "Il était une fois\n";
  printf("%s", chaine);

  //Question 1
  char *pchar = chaine;
  printf("%p %p\n", &chaine, pchar);
  char *pOccurenceC = recherche(pchar, 'o');
  printf("%p\n", pOccurenceC);
  printf("Il y a %d occurrence(s) de t dans la chaine\n", compte(pchar, 't'));
}
Exemple #5
0
int	main(int argc, char *argv[])
{
  int	i;
  int	j;
  int	arg;
  int	total;
  int	ligne;
  int	car;
  int	mot;

  total = 0;
  ligne = 0;
  j = 0;
  arg = 0;
  if (argc <= 1)
    {
      fprintf(stderr,"error: vous n'avez pas rentré d'arguments\n");
      return (EXIT_FAILURE);
    }
  if (argv[1][0] == '-')
    arg++;
  for (i = arg+1; i < argc; i++)
    {
      ligne = 0;
      car = 0;
      mot = 0;
      if (compte(argv[i],&ligne, &car, &mot) == 0)
	fprintf(stderr,"%s failed\n",argv[i]);
      if (arg == 0){
	printf("%d \t %d \t %d \t %s\n",ligne,mot,car,argv[i]);
      }
      else {
	j = 1;
	while (argv[1][j])
	{
	  if (argv[1][j] == 'l'){
	    printf("%d \t", ligne);
	  }
	  if (argv[1][j] == 'm')
	    printf("%d \t", mot);
	  if (argv[1][j] == 'c')
	    printf("%d \t", car);
	  j++;
	}
      printf("%s\n", argv[i]);
      }
      total = total + ligne;
    }
  printf("%d	total\n",total);
  return (EXIT_SUCCESS);
}
Exemple #6
0
void compte(noeud *N, int level, int *C)
{
  fils *F;
  switch(N->type)
    {
    case SERIE: C[4*level]++; break;
    case PARALLELE: C[4*level+1]++; break;
    case PREMIER: C[4*level+2]++; break;
    case FEUILLE: C[4*level+3]++; break;
    }
  if(N->type!=FEUILLE)  
    for(F=N->fils;F!=NULL;F=F->suiv)
      compte(F->pointe, level+1, C);
}
Exemple #7
0
int main(){
	int c;
	int tab[TAILLE];
	int h[TAILLE];
	int point[2];
	point[0] = 0;
	point[1] = 400;
	printf("Initialisation de tab :\n");
	c = init_tab(tab, TAILLE);
	printf("La valeur %d est presente %d fois.\n",V,compte(tab,c,V));
	printf("La valeur maximale est : %d\n",max_notes(tab,c));
	printf("\nTableau d'occurences :\n");
	histogramme(tab,h,c);
	CINI_open_window(FENETRE,FENETRE,"fenetre");
	CINI_fill_window("white");
	/*dessiner_baton(point,50,100,"red"); */
	printf("Dessiner histogramme\n:");
	dessiner_histogramme(tab,h,point,c,20,100,"red");
	return 0;
}
Exemple #8
0
void test(int n, long int ppm, int *C)
{
  /*genere un graphe aleatoire, l'affiche, le decompose*/
  graphe G;

  int i,j;
  adj *a;
  noeud *R;


  srandom((unsigned)time(NULL));

  G.n=n;
  G.G=(adj **)malloc(n*sizeof(adj *));

  for(i=0;i<n;i++)
    G.G[i]=NULL;

  printf("Programme test : generation d'un graphe aleatoire de %i sommets\n",n);
  for(i=0; i<n; i++)
    {
      if(VERBEUX)
	{
	  printf("Ajacence de %i: ",i+1);
	  for(a=G.G[i]; a!=NULL; a=a->suiv) 
	    printf("%i ",1+a->s);
	}
      for(j=i+1;j<n;j++)
	{
	if( (random()%1000000L) < ppm )
	  {	
	    // ajoute j a l'adjacence de i
	    a=(adj *)malloc(sizeof(adj));
	    a->s=j;
	    a->suiv=G.G[i];
	    G.G[i]=a;
	    // et reciproquement
	    a=(adj *)malloc(sizeof(adj));
	    a->s=i;
	    a->suiv=G.G[j];
	    G.G[j]=a;
	    if(VERBEUX)
	      printf("%i ",j+1);
	  }
	}
      if(VERBEUX)
	printf("\n");
    }

  // appel de la fonction de decomposition
  R = decomposition_modulaire(G);

  // affichage de l'arbre
  if(VERBEUX)
    printarbre(R);

  compte(R,0,C);
  printf("Statistiques sur l'arbre de decomposition:\n");
  if(C[0])
    printf("La racine est Serie\n");
  else if(C[1])
    printf("La racine est Parrallele\n");
  else
    printf("La racine est Premier \n");
  for(i=1 ; i<NIV ; i++)
    {
      printf("Niveau %i: %i modules (S-P-Pr= %i - %i - %i) et %i feuilles\n",i,
       C[4*i]+C[4*i+1]+C[4*i+2], C[4*i], C[4*i+1], C[4*i+2],C[4*i+3]);  
      if(i<NIV-1 && C[4*i+4]+C[4*i+5]+C[4*i+6]+C[4*i+7]==0)
	break;
    }
  printf("\n");
}