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

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

8 comments:

Unknown 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

Balaji Travels said...

Thanks for sharing the information
chennai to tirupati package
best tirupati package from chennai
chennai to tirupati package tour
chennai to tirupati tour package
tirupati package tour from chennai
tirupati tour package from chennai
chennai tirupati package one day by car
chennai to tirupati one day tour package
chennai to tirupati darshan package
chennai to tirupati car package
chennai to tirupati darshan package car rental package
one day tirupati tour package from chennai

Happieeee said...

Thanks for sharing this blog
We are providing tirupati package at reasonable price

chennai to tirupati packages
one day package from chennai to tirupati by car
chennai to tirupati package by car
chennai to tirupati car package
tirupati package tour from chennai

vivikhapnoi said...

The article was up to the point and described the information very effectively.

vé máy bay tết nguyên đán

phong ve may bay gia re

lịch bay sài gòn đà nẵng

vé máy bay đi nha trang tháng 11

lịch bay hà nội phú quốc vietjet air

vé máy bay đi quy nhơn giá rẻ

vivikhapnoi said...

Fantastic!! you are doing good job! I impressed. Many bodies are follow to you and try to some new.. After read your comments I feel; Its very interesting and every guys sahre with you own works. Great!!
Máy bay từ Hàn Quốc về Việt Nam

chuyến bay từ Sydney đến thành phố hồ chí minh

vé máy bay từ san francisco về việt nam

Vé máy bay từ Đài Trung về Việt Nam

vé máy bay từ houston về việt nam

giá vé máy bay từ canada về việt nam