| | |
98% done
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2005
Posts: 31
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include<iostream.h> #include<conio.h> #include<stdio.h> int main() { void palcheck(char str[]); char ans; char str[20]; do { cout<<"Enter the string to check if it is a palindrome. "; gets(str); palcheck(str); cout<<"\nEnter Y to continue. "; cin>>ans; }while (ans=='y'||ans=='Y'); } void palcheck(char str[]) { int l=0,k=0,flag; for(int i=0;str[i]!='\0';i++) l=l+1; k=l; for(int j=0;j<l/2;j++) { k--; if(str[j]==str[k]) flag=1; else {flag=0; break;} } if(flag==0) cout<<"\nString is not a palindrome. "; else cout<<"String is a palindrome. "; }
•
•
•
•
Originally Posted by sahil_logic
i am almost done . just a small error. it is not asking for new input which i want it to do . it is storing the previous value. some problem around the do loop but not able to figure out. i think it has to do something with declaration of variable.C++ Syntax (Toggle Plain Text)
#include<iostream.h> #include<conio.h> #include<stdio.h> int main() { void palcheck(char str[]); char ans; char str[20]; do { cout<<"Enter the string to check if it is a palindrome. "; gets(str); palcheck(str); cout<<"\nEnter Y to continue. "; cin>>ans; }while (ans=='y'||ans=='Y'); } void palcheck(char str[]) { int l=0,k=0,flag; for(int i=0;str[i]!='\0';i++) l=l+1; k=l; for(int j=0;j<l/2;j++) { k--; if(str[j]==str[k]) flag=1; else {flag=0; break;} } if(flag==0) cout<<"\nString is not a palindrome. "; else cout<<"String is a palindrome. "; }
- Don't use gets(). It's dangerous. (Buffer overruns.)
- In C++, <stdio.h> becomes <cstdio>.
- <conio.h> is non-standard. You're not using it anywhere.
- <iostream.h> is also deprecated. Use
instead.C++ Syntax (Toggle Plain Text)- #include <iostream>
- using namespace std;
![]() |
Other Threads in the C++ Forum
- Previous Thread: Timer Countdown
- Next Thread: major help
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





