美元兑换卢比的C程序
有没有办法编写一个C
程序来将美元
转换为印度卢比
(反之亦然)。转换参数不应该是硬编码的,而是动态的。更珍贵的是,它应该自动获取卢比
与美元
的最新价值(来自互联网)?
Is there a way to write a C
program to convert say Dollar
to Indian Rupee
(or visa-versa). The conversion parameter should not be hard coded but dynamic. More preciously it should get the latest value of Rupee
vs Dollar
automatically(from Internet) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
第 1 步是获取最新的转化率。您可以为此使用网络服务。有很多可用的。您可以尝试这个。
请求:
响应:
要发送请求,您可以使用 cURL。
收到响应后,只需对其进行解析即可获取速率。一旦您获得了汇率,您就可以轻松编写要转换的程序。
编辑:
如果您不习惯使用 cURL,您可以使用旧的
system
和wget
。为此,您需要首先构建 URL,如下所示:www.webservicex .net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=USD
然后从 C 程序中您可以执行以下操作:
此后,转换率以 XML 形式保存在文件
result.html
中。只需打开它并解析它即可。如果您使用的是Windows,则需要安装wget for windows(如果没有)。您可以在此处获取它。
Step 1 would be to get the latest conversion rate. You can use a web-service for that. There are many available. You can try this.
Request:
Response:
For sending the request you can make use of cURL.
Once you have the response, just parse it to get the rate. Once you've the rate you can easily write the program to convert.
EDIT:
If using cURL is something you are not comfortable with you can make use of good old
system
andwget
. For this you need to construct the URL first like:www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=USD
then from the C program you can do:
After this the conversion rate is in the file
result.html
as XML. Just open it and parse it.If you are using windows, you need to install wget for windows if you don't have it. You can get it here.
首先,你需要找到一个可以提供转化率的服务器。之后,您编写程序以从该服务器获取费率,并在程序中进一步使用这些信息。
本网站,http://www.csharphelp.com/ 2007/01/currency-converter-server-with-c/ 虽然提供了 C# + Web 的教程,但它可以为您提供如何操作的一般技术思路。
First, you need to find a server that can provides the conversion rate. After that, you write your program to fetch the rates from that server and use those information further in your program.
This site, http://www.csharphelp.com/2007/01/currency-converter-server-with-c/ although provides a tutorial for C# + Web, it can give you a general technical idea of how to do it.