summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2022-10-04 10:03:43 -0400
committerBenjamin Chausse <benjamin@chausse.xyz>2022-10-04 10:03:43 -0400
commitcb9cbfeba14ef6dbdf04d15030109169ea2d428c (patch)
treeff0647fcc7c38c868930a7b7b686f245efa8aac6
parentc956594b3b9349a982fe4721b31de922b6cacd88 (diff)
Fonction palindromeHEADmaster
-rw-r--r--palindrome.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/palindrome.c b/palindrome.c
new file mode 100644
index 0000000..0d467d5
--- /dev/null
+++ b/palindrome.c
@@ -0,0 +1,38 @@
+/* palindrome.c
+ * ----------------------------------------------------------------------------
+ * "THE BEER-WARE LICENSE" (Revision 42):
+ * <benjamin@chausse.xyz> wrote this file. As long as you retain this notice
+ * you can do whatever you want with this stuff. If we meet some day, and you
+ * think this stuff is worth it, you can buy me a beer in return.
+ * Benjamin Chausse
+ * ----------------------------------------------------------------------------
+ */
+
+#include <stdio.h>
+#include "format.h"
+#include "testData.h"
+
+int palindrome(char *s){
+ int len = 0;
+ while (s[len]!= '\0'){
+ len ++;
+ }
+ int j = len;
+ for (int i=0; i<len/2;i++){
+ j--;
+ printf("%c-",s[i]);
+ printf("%c\n",s[j]);
+ if (s[i] != s[j]){
+ return 0;
+ }
+ }
+ return 1;
+}
+
+int main(){
+ char *word = "tenet";
+ printf("%s: %d\n",word,palindrome(word));
+ word = "automobile";
+ printf("%s: %d\n",word,palindrome(word));
+ return 0;
+}