All pastes #2053835 Raw Edit

Eusebus

public text v1 · immutable
#2053835 ·published 2011-05-04 14:52 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <assert.h>#define OK 0#define KO 1int is_pal(const char *str);char *pal_str(const char *str);int main(void) /* Reprise du main de -ed- */{    assert(is_pal("") == OK);    assert(is_pal("a") == OK);    assert(is_pal("ana") == OK);    assert(is_pal("anna") == OK);    assert(is_pal("a   n na") == OK); /* pour montrer la gestion des espaces */    assert(is_pal("AnNa") == OK);    assert(is_pal("anma") == KO);    assert(is_pal("azerty") == KO);    assert(is_pal("azertytreza") == OK);    assert(is_pal("Azertytreza") == OK);    assert(is_pal("azertyytreza") == OK);    assert(is_pal("azertyyyyyyyytreza") == OK);    puts("P A S S E D");    return EXIT_SUCCESS;}int is_pal(const char *str){	char *s = pal_str(str);	size_t size = strlen(s);	size_t i;	int pal = OK;	for(i = 0; i < (size / 2) && pal == OK; i++)	{		if(*(s + i) != *(s + size - i - 1))			pal = KO;	}	free(s);	return pal;}char *pal_str(const char *str){	char *s = malloc((strlen(str) + 1) * sizeof(char));	char *ret = s;	if(s != NULL)	{		for(; *str; str++)			if(*str != ' ')				*(s++) = tolower(*str);	}	else	{		perror("malloc()");		exit(EXIT_FAILURE);	}	return ret;}