美元兑换卢比的C程序

发布于 2024-08-20 19:00:06 字数 152 浏览 5 评论 0原文

有没有办法编写一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

删除会话 2024-08-27 19:00:06

第 1 步是获取最新的转化率。您可以为此使用网络服务。有很多可用的。您可以尝试这个

请求:

GET /CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=USD HTTP/1.1
Host: www.webservicex.net

响应:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<double xmlns="http://www.webserviceX.NET/">SOME_RATE_IN_DOUBLE</double>

要发送请求,您可以使用 cURL。

收到响应后,只需对其进行解析即可获取速率。一旦您获得了汇率,您就可以轻松编写要转换的程序。

编辑:

如果您不习惯使用 cURL,您可以使用旧的 systemwget。为此,您需要首先构建 URL,如下所示:

www.webservicex .net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=USD

然后从 C 程序中您可以执行以下操作:

char cmd[200];
char URL[] = "www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=USD";
sprintf(cmd,"wget -O result.html '%s'",URL); // ensure the URL is in quotes.
system(cmd);

此后,转换率以 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:

GET /CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=USD HTTP/1.1
Host: www.webservicex.net

Response:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<double xmlns="http://www.webserviceX.NET/">SOME_RATE_IN_DOUBLE</double>

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 and wget. 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:

char cmd[200];
char URL[] = "www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=USD";
sprintf(cmd,"wget -O result.html '%s'",URL); // ensure the URL is in quotes.
system(cmd);

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.

2024-08-27 19:00:06

首先,你需要找到一个可以提供转化率的服务器。之后,您编写程序以从该服务器获取费率,并在程序中进一步使用这些信息。

本网站,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文