| | |
Palindrome Check, Dynamic Memory
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Just another way to check if a word is palindromic or not.
In my country (Greece) if a word is palindromic we say it is
"καρκινική" that's why i named the fuction in the code kark().
-What it does?
If we would say that word has n letters,then this
compares the first with the n letter, next the second with the n-1 letter and so on..
e.g. let's take the name "anna"
compares the first 'a' with the last 'a'
and the two 'n' in between.
Hope it's helpful...
In my country (Greece) if a word is palindromic we say it is
"καρκινική" that's why i named the fuction in the code kark().
-What it does?
If we would say that word has n letters,then this
compares the first with the n letter, next the second with the n-1 letter and so on..
e.g. let's take the name "anna"
compares the first 'a' with the last 'a'
and the two 'n' in between.
C Syntax (Toggle Plain Text)
a n n a |--| |-----|
Hope it's helpful...
Last edited by panagos; Oct 29th, 2009 at 5:14 pm.
#include <stdio.h> #include <stdlib.h> #include <string.h> int kark(char *); int main() { char *s; int count; printf("give the length of the word:"); scanf("%d",&count); s=(char *)malloc(count+1); printf("give word:"); scanf("%s",s); if(kark(s))/*==1)*/ printf("\n\tThe word is palindromic.\n"); else printf("\n\tThe word is NOT palindromic.\n"); return 0; } int kark(char *x) { int i,j,flag; flag=1; i=0; j=strlen(x)-1; while((flag==1)&&(x[i]!='\0')) { if(x[i]==x[j]) flag=1; else{ flag=0;} j--; i++; } return flag; }
Similar Threads
- Deleted memory still accessible? (C++)
- Problems with dynamic memory (C++)
- Dynamic memory for an array of objects (C++)
- Static and Dynamic Memory Allocations...Advan's & Disadvan's??? (Computer Science)
- regarding dynamic memory allocation (C)
- Dynamic memory allocation homework (C++)
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api append array arrays bash binarysearch centimeter char character cm convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic feet fflush fgets file floatingpointvalidation fork frequency function getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide infiniteloop initialization interest intmain() kilometer lazy license linked linkedlist linux linuxsegmentationfault list match matrix meter microsoft multi mysql oddnumber odf open openwebfoundation pattern pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition scheduling segmentationfault send shape single socketprogramming spoonfeeding stack standard strchr string strings structures student suggestions system test testautomation unix urboc user voidmain() win32api windows.h



