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

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

9 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

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

Các mẫu nhà đẹp said...

This is one of the most incredible blogs Ive read in a very long time.
nhà vườn cấp 4 đẹp

xây nhà cho thuê

biệt thự nhà vườn 2 tầng

nhà 3 tầng hiện đại

thi công nội thất cafe

nhà ống đẹp

Các mẫu nhà đẹp said...

An awesome blog thanks a lot for giving me this great opportunity to write on this.
Trang trí phòng khách 

Các sử dụng kệ trang trí

Mẹo chọn ghế sofa cho gia đình nuôi thú cưng

Những lưu ý trước khi bạn định thuê trọ

Nội thất đẹp cho phòng khách

Trang trí nhà với màu duy nhất có nên không