| | |
Palindrome Check, Dynamic Memory
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; 30 Days Ago 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 |
#include * adobe ansi array asterisks binarysearch centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fgets file floatingpointvalidation fork function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop input interest intmain() iso kernel keyboard kilometer license linked linkedlist linux list locate looping lowest matrix meter microsoft mqqueue number oddnumber opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault windowsapi



