Friday, September 27, 2013

Basic Math Challege OOP344

A student was asking about "sscanf" and how it works for the week 3 ToDo (basicMath challenge), so here is the example:
#include <cstdio>
#include <iostream>
using namespace std;

int main(){
  double d;
  char num1[80] = "1234.5678";
  char num2[80] = "1234.5678a";
  char num3[80] = "12a34.5678";
  char num4[80] = "a1234.5678";
  char ch ;
  int ret;
  d = 0.0;
  ch = 'X';
  ret = sscanf(num1,"%lf%c", &d, &ch);
  cout<<ret<<endl;
  cout<<ch<<endl;
  cout<<d<<endl;
  cout<<"----------------------------"<<endl;
  d = 0.0;
  ch = 'X';
  ret = sscanf(num2,"%lf%c", &d, &ch);
  cout<<ret<<endl;
  cout<<ch<<endl;
  cout<<d<<endl;
  cout<<"----------------------------"<<endl;
  d = 0.0;
  ch = 'X';
  ret = sscanf(num3,"%lf%c", &d, &ch);
  cout<<ret<<endl;
  cout<<ch<<endl;
  cout<<d<<endl;
  cout<<"----------------------------"<<endl;
  d = 0.0;
  ch = 'X';
  ret = sscanf(num4,"%lf%c", &d, &ch);
  cout<<ret<<endl;
  cout<<ch<<endl;
  cout<<d<<endl;
  cout<<"----------------------------"<<endl;
  return 0;
}
output:
1
X
1234.57
----------------------------
2
a
1234.57
----------------------------
2
a
12
----------------------------
0
X
0

----------------------------

4 comments:

Mahalakshmi Travels Selva Kumar said...

Very informative post. I was looking for information about this topic and this post really helped me a lot. Thanks for sharing.

One Day Tirupati Tour Package From Chennai
Tirupati Tour Package From Chennai
Chennai To Tirupati Car Rental

ninjaninji18 said...

Thanks for the wonderful post and it is very useful for the customers who need to have an cab service with more safe and safety.
Chennai to Tirupati Car Rental
Chennai to Pondicherry Taxi

Sri Balaji Tours and Travel said...

Great one to read.



BANGALORE TO TIRUPATI PACKAGE
BANGALORE TO TIRUPATI CAR PACKAGES
BANGALORE TO TIRUPATI TOUR PACKAGE
BANGALORE TO TIRUPATI TOUR PACKAGES
BEST TIRUPATI PACKAGE FROM BANGALORE
BANGALORE TO TIRUPATI PACKAGES
ONE DAY TIRUPATI PACKAGE FROM BANGALORE
TIRUPATI BALAJI DARSHAN PACKAGE FROM BANGALORE
BANGALORE TO TIRUPATI TOUR PACKAGES
BANGALORE TO TIRUPATI CAR PACKAGE
Best Car Package from Bangalore to Tirupati
Tirupati Balaji Darshan Package from Bangalore
Tirupati Trip from Bangalore
car package from bengaluru to tirupati
bangalore to tirumala tour
Tirupati Trip from Bangalore
Bangalore to Tirupati Quick Darshan Package
Bangalore to Tirupati Family Package
Bangalore to Tirupati Package Tour
Bangalore to Tirumala Package



ninjaninji18 said...

Thanks for the post it was really good post for the long journey tours. We need more blog for us and it is very useful for the users. It helps us to hire a car rental service for the peoples.
Chennai to Tirupati Car Rental
Chennai Car Rental
Chennai to Pondicheery Taxi