728x90 AdSpace

Latest Article

Program Convert symbolic String into Integer in C++ Code





Write a program in C++ that read a CString and discard all the symbols except the digits.converts the CString to an integer and store this integer in variable and print it. (10)
Sample Output:


Enter a CString:12ty12
String convert to integer:1212
Enter a CString:69$
String convert to integer:69
Hints:Use strlen,isdigit,atoi functions



Solution:

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
char str[50];
char intStr[50];
int index=0;
cout<<"Enter a CString :";
cin>>str;
for(int i=0;i<strlen(str);i++)
{
if(isdigit(str[i]))
intStr[index++]=str[i];
}
intStr[index]='\0';
int value=atoi(intStr);
cout<<"CSting to Integer :"<<value<<endl;
system("PAUSE");
return(0);
}

no image
  • Title : Program Convert symbolic String into Integer in C++ Code
  • Posted by :
  • Date : 11:44
  • Labels :





  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment

Top