<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>憂藍夢境‧部落格 &#187; C</title>
	<atom:link href="http://blog.linym.net/archives/tag/c/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.linym.net</link>
	<description>我的學習心得、筆記</description>
	<lastBuildDate>Fri, 09 Dec 2011 12:33:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>使用 C# 呼叫 MATLAB Function</title>
		<link>http://blog.linym.net/archives/564</link>
		<comments>http://blog.linym.net/archives/564#comments</comments>
		<pubDate>Thu, 10 Sep 2009 07:49:21 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[MATLAB]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.linym.net/?p=564</guid>
		<description><![CDATA[最近在寫一些演算法的程式，經常要在一堆程式和檔案切換來切換去的，跑完數據還要開 MATLAB 畫圖，一直重複這些動作實在是很麻煩，所以把它寫成 Windows Form 用滑鼠點一點就 OK 了，其中繪圖部份就要利用 C# 去 call MATLAB 來作，查了許多資料，發現有很多種方法，但比較簡單方便的應該是用 MATLAB Builder NE for .NET 將 MATLAB 程式編譯成 .NET 可執行的元件。 1. 首先準備好你要 compiler 的 M-file，測試的 M-file 如下(由檔案讀取 x, y 數據曲線圖)： function rmse(file) data = load(file); x = data(:,1); y = data(:,2); plot(x,y,&#039;LineWidth&#039;,1); xlabel(&#039;Iteration&#039;); ylabel(&#039;RMS error&#039;); 2. 開啟 MATLAB 並在 command windows 輸入：deploytool [...]]]></description>
			<content:encoded><![CDATA[<p>最近在寫一些演算法的程式，經常要在一堆程式和檔案切換來切換去的，跑完數據還要開 MATLAB 畫圖，一直重複這些動作實在是很麻煩，所以把它寫成 Windows Form 用滑鼠點一點就 OK 了，其中繪圖部份就要利用 C# 去 call MATLAB 來作，查了許多資料，發現有很多種方法，但比較簡單方便的應該是用 <a href="http://www.mathworks.com/products/netbuilder/" target="_blank">MATLAB Builder NE for .NET</a> 將 MATLAB 程式編譯成 .NET 可執行的元件。</p>
<p>1. 首先準備好你要 compiler 的 M-file，測試的 M-file 如下(由檔案讀取 x, y 數據曲線圖)：</p>
<pre title="code" class="cpp">

function rmse(file)

data = load(file);
x = data(:,1);
y = data(:,2);

plot(x,y,&#039;LineWidth&#039;,1);

xlabel(&#039;Iteration&#039;);
ylabel(&#039;RMS error&#039;);
</pre>
<p>2. 開啟 MATLAB 並在 command windows 輸入：<strong>deploytool</strong><br />
    新建一個 project，名稱為 rmse。<br />
    <a href="http://blog.linym.net/wp-content/uploads/2009/09/01.JPG"><img src="http://blog.linym.net/wp-content/uploads/2009/09/01.JPG" alt="New Project" title="New Project" width="646" height="451" class="alignnone size-full wp-image-567" /></a><br />
    選擇 .NET component<br />
    <a href="http://blog.linym.net/wp-content/uploads/2009/09/2.JPG"><img src="http://blog.linym.net/wp-content/uploads/2009/09/2.JPG" alt=".NET component" title=".NET component" width="510" height="510" class="alignnone size-full wp-image-571" /></a><br />
    將 M-file 加入，然後按<strong> Build the project</strong>，編譯完成會產生 rmse.dll<br />
<a href="http://blog.linym.net/wp-content/uploads/2009/09/3.JPG"><img src="http://blog.linym.net/wp-content/uploads/2009/09/3.JPG" alt="Add file" title="Add file" width="646" height="451" class="alignnone size-full wp-image-574" /></a></p>
<p>3. 將 .dll 加入 Visual Studio 參考(Reference)<br />
   在方案總管右鍵選「加入參考」>「瀏覽」，將剛剛編譯完成的 .dll 以及 MATLAB 安裝目錄底下的 toolbox\dotnetbuilder\bin\win32\v2.0\MWArray.dll 加入。</p>
<p>4. 加入 Namespace<br />
using MathWorks.MATLAB.NET.Arrays;<br />
using rmse;</p>
<p>5. 使用方式<br />
    Rmse demo = new Rmse();<br />
    MWArray fileName = @"rmse.txt";<br />
    demo.rmse(fileName);</p>
<p>※ <a href='http://blog.linym.net/wp-content/uploads/2009/09/CSharp_Matlab.rar'>demo 範例原始碼下載</a></p>
<p>※ 如果想在沒安裝 MATLAB 的電腦上執行，需安裝 MATLAB Compiler Runtime (MCR)，檔案在安裝目錄的 toolbox\compiler\deploy\win32\MCRInstaller.exe，大小約 150MB</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/564/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>TwSMS 發簡訊 (Linux C 版)</title>
		<link>http://blog.linym.net/archives/216</link>
		<comments>http://blog.linym.net/archives/216#comments</comments>
		<pubDate>Sun, 20 Jan 2008 17:39:20 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[TwSMS]]></category>
		<category><![CDATA[傳簡訊]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/216</guid>
		<description><![CDATA[台灣簡訊(TwSMS)是國內一家線上傳簡訊的服務商，提供文字簡訊、語音簡訊等服務，價格也很合理，最重要的是有提供 API 介面，方便用戶在自己的程式中加入發送簡訊功能，官網已經有提供不少範例(PHP/ASP/JSP/Java/Perl/VB/BCB/Delphi)，這邊也有 Ruby 的版本，不過就是沒看到 C 的，所以大略寫了一個 Linux C 版本，打算加入自己的嵌入式專題使用。 TwSMS 提供的 API 很簡單，只要由 HTTP 對 API server 發送 Request 即可，接著 server 就會回傳結果。程式先建立一個 socket 連線，然後發送簡訊，最後再擷取回傳碼檢查是否成功。 #include &#60;stdio.h&#62; #include &#60;stdlib.h&#62; #include &#60;string.h&#62; #include &#60;sys/socket.h&#62; #include &#60;netinet/in.h&#62; #include &#60;arpa/inet.h&#62; #include &#60;netdb.h&#62; int main() { /* TWSMS 相關設定 */ char *username = &#34;username&#34;; // 帳號 char *password = [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.twsms.com/" target="_blank">台灣簡訊</a>(TwSMS)是國內一家線上傳簡訊的服務商，提供文字簡訊、語音簡訊等服務，價格也很合理，最重要的是有提供 API 介面，方便用戶在自己的程式中加入發送簡訊功能，官網已經有提供不少範例(PHP/ASP/JSP/Java/Perl/VB/BCB/Delphi)，<a href="http://github.com/cfc/twsmsr/tree/master" target="_blank">這邊</a>也有 Ruby 的版本，不過就是沒看到 C 的，所以大略寫了一個 Linux C 版本，打算加入自己的嵌入式專題使用。</p>
<p>TwSMS 提供的 API 很簡單，只要由 HTTP 對 API server 發送 Request 即可，接著 server 就會回傳結果。程式先建立一個 socket 連線，然後發送簡訊，最後再擷取回傳碼檢查是否成功。</p>
<pre title="code" class="cpp">

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;sys/socket.h&gt;
#include &lt;netinet/in.h&gt;
#include &lt;arpa/inet.h&gt;
#include &lt;netdb.h&gt;

int main()
{
	/* TWSMS 相關設定 */
	char *username = &quot;username&quot;;   // 帳號
	char *password = &quot;password&quot;; // 密碼
	char *type = &quot;now&quot;;         // 發送型態
	char *mobile = &quot;0912xxxxxx&quot;; // 電話
	char *message = &quot;簡訊測試&quot;; // 簡訊內容
	char *encoding = &quot;big5&quot;;    // 簡訊內容編碼
	char *popup = &quot;&quot;;          // 使用 POPUP 顯示
	char *mo = &quot;&quot;;             // 使用雙向簡訊
	char *vldtime = &quot;86400&quot;;    // 簡訊有效期限(秒)
	char *dlvtime = &quot;&quot;;         // 預約時間

	int sockfd;
	int len = 0;
	char *host = &quot;api.twsms.com&quot;;
	char msg[512], MSGData[512], buf[512];
	char *res, *checkRes;
	struct sockaddr_in address;
	struct hostent *hostinfo;

	bzero(&amp;address, sizeof(address));
	hostinfo = gethostbyname(host);
	if (!hostinfo) {
		fprintf(stderr, &quot;no host: %s\n&quot;, host);
		exit(1);
	}
	address.sin_family = AF_INET;
	address.sin_port = htons(80);
	address.sin_addr = *(struct in_addr *)*hostinfo-&gt;h_addr_list;

	/* Create socket */
	sockfd = socket(AF_INET, SOCK_STREAM, 0);

	/* Connect to server */
	if (connect(sockfd, (struct sockaddr *)&amp;address, sizeof(address)) == -1) {
		perror(&quot;connect faild!\n&quot;);
		exit(1);
	}

	/* Request string */
	len = snprintf(msg, 512,
				  &quot;username=%s&amp;password=%s&amp;type=%s&amp;encoding=%s&amp;popup=%s&amp;mo=%s&amp;mobile=%s&quot;
				  &quot;&amp;message=%s&amp;vldtime=%s&amp;dlvtime=%s&quot;, username, password, type, encoding,
				  popup, mo, mobile, message, vldtime, dlvtime);

	/* HTTP request content */
	snprintf(MSGData, 512,
			&quot;POST /send_sms.php HTTP/1.1\r\n&quot;
			&quot;Host: %s\r\n&quot;
			&quot;Content-Length: %d\r\n&quot;
			&quot;Content-Type: application/x-www-form-urlencoded\r\n&quot;
			&quot;Connection: Close\r\n\r\n&quot;
			&quot;%s\r\n&quot;, host, len, msg);

	/* Send message */
	send(sockfd, MSGData, strlen(MSGData), 0);

	/* Response message */
	recv(sockfd, buf, 512, 0);

	for (res = strtok(buf, &quot;\n&quot;); strncmp(res, &quot;resp&quot;, 4) != 0; res = strtok(NULL, &quot;\n&quot;));
	checkRes = strtok(res, &quot;=&quot;);
	checkRes = strtok(NULL, &quot;=&quot;);

	if (atoi(checkRes) &lt;= 0) {
		printf(&quot;傳送失敗\n&quot;);
	} else {
		printf(&quot;傳送完成\n&quot;);
	}

	close(sockfd);
	return 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/216/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>C 語言中 printf 的問題(續)</title>
		<link>http://blog.linym.net/archives/186</link>
		<comments>http://blog.linym.net/archives/186#comments</comments>
		<pubDate>Sun, 30 Sep 2007 03:03:53 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/186</guid>
		<description><![CDATA[在前一篇當中提到了 printf 結果異常的問題，在睡前翻了一下手邊借來的「C Primer Plus」，沒想到就有提到這個問題，印象中其他書籍似乎都沒有講到，C Primer 系列果然是好書！ 簡單來說就是 C 語言中，compiler 可以選擇先計算函數中的哪個參數，以增加編譯程式的效率，所以前一篇的例子： printf(&#34;%d, %d&#34;, age, age++); compiler 很可能會先算第二個參數，先改變了 num 數值，這樣就造成結果不如預期了。 在「C Primer Plus 5/e 中文精華版」第五章有寫道，遵循以下原則可以避免這些問題： 請勿在函數當中，對使用不止一次的參數使用遞增或遞減運算子。 請勿在運算式當中，對使用不止一次的變數使用遞增或遞減運算子。 第一點就是上面所說的例子，第二點的例子如下： n = 3; y = n++ + n++; 在 C 標準中並沒有定義這行程式會如何執行，是哪一個先加 1 再運算，還是都先不加，造成了含糊不清的結果，應當避免這種寫法。]]></description>
			<content:encoded><![CDATA[<p>在<a href="http://blog.linym.net/archives/185">前一篇</a>當中提到了 printf 結果異常的問題，在睡前翻了一下手邊借來的「C Primer Plus」，沒想到就有提到這個問題，印象中其他書籍似乎都沒有講到，C Primer 系列果然是好書！</p>
<p>簡單來說就是 C 語言中，compiler 可以選擇先計算函數中的哪個參數，以增加編譯程式的效率，所以前一篇的例子：</p>
<pre title="code" class="c">

printf(&quot;%d, %d&quot;, age, age++);
</pre>
<p>compiler 很可能會先算第二個參數，先改變了 num 數值，這樣就造成結果不如預期了。</p>
<p>在「<a href="http://www.books.com.tw/exep/prod/booksfile.php?item=0010322617" target="_blank">C Primer Plus 5/e 中文精華版</a>」第五章有寫道，遵循以下原則可以避免這些問題：</p>
<blockquote>
<ol>
<li>請勿在函數當中，對使用不止一次的參數使用遞增或遞減運算子。</li>
<li>請勿在運算式當中，對使用不止一次的變數使用遞增或遞減運算子。</li>
</ol>
</blockquote>
<p>第一點就是上面所說的例子，第二點的例子如下：</p>
<pre title="code" class="c">

n = 3;
y = n++ + n++;
</pre>
<p>在 C 標準中並沒有定義這行程式會如何執行，是哪一個先加 1 再運算，還是都先不加，造成了含糊不清的結果，應當避免這種寫法。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/186/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>C 語言中 printf 的問題</title>
		<link>http://blog.linym.net/archives/185</link>
		<comments>http://blog.linym.net/archives/185#comments</comments>
		<pubDate>Sat, 29 Sep 2007 16:00:10 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.linym.net/archives/185</guid>
		<description><![CDATA[今天有個學妹問我一個 C 程式的問題：下面程式的結果為何？ #include &#60;stdio.h&#62; int main(void) { int age = 20; printf(&#34;You are now %d, and will be %d in one year&#34;, age, age++); return 0 ; } 自認觀念還不錯的我直接就回答「20, 20」。但沒想到實際跑的答案竟然是「21, 20」，這真是出乎意料的結果啊！ 馬上另外測試了其他有 printf 函式的語言，如 Java、PHP，結果也都是正確的「20, 20」，所以不知道是 C printf 的 bug 還是什麼原因，希望有人能解答。 請看：C 語言中 printf 的問題(續)]]></description>
			<content:encoded><![CDATA[<p>今天有個學妹問我一個 C 程式的問題：下面程式的結果為何？</p>
<pre title="code" class="php">

#include &lt;stdio.h&gt;
int main(void)
{
    int age = 20;
    printf(&quot;You are now %d, and will be %d in one year&quot;, age, age++);
    return 0 ;
}
</pre>
<p>自認觀念還不錯的我直接就回答「20, 20」。但沒想到實際跑的答案竟然是「21, 20」，這真是出乎意料的結果啊！</p>
<p>馬上另外測試了其他有 printf 函式的語言，如 Java、PHP，結果也都是正確的「20, 20」，所以不知道是 C printf 的 bug 還是什麼原因，希望有人能解答。</p>
<p>請看：<a href="http://blog.linym.net/archives/186">C 語言中 printf 的問題(續)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/185/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>OpenGL-海龜作圖法</title>
		<link>http://blog.linym.net/archives/116</link>
		<comments>http://blog.linym.net/archives/116#comments</comments>
		<pubDate>Tue, 16 Jan 2007 04:22:38 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[程式筆記]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[海龜作圖]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/116</guid>
		<description><![CDATA[海龜作圖法(Turtle Graphics)，意思是模仿海龜移動的方式，只能前進及左右轉，而將海龜的尾巴當作畫筆，可以放下及抬起。 本範例為二維空間，使用 OpenGL 搭配 C++ 實做。 程式功能介紹： 1、由 turtle.txt 檔案讀入作圖指令。 2、INIT - 設定海龜初始位置。(x 軸, y 軸, 龜頭角度) 3、PEN - 設定尾巴狀態。(0 抬起 / 1放下) 4、FW - 海龜向前移動。(移動長度) 5、RIGHT - 海龜右轉角度。(角度) 6、LEFT - 海龜左轉角度。(角度) #include &#60;iostream&#62; #include &#60;fstream&#62; #include &#60;cstring&#62; #include &#60;cmath&#62; #include &#60;GL/glut.h&#62; using namespace std; const GLfloat PI = 3.141593; class Turtle { private: [...]]]></description>
			<content:encoded><![CDATA[<p>海龜作圖法(Turtle Graphics)，意思是模仿海龜移動的方式，只能前進及左右轉，而將海龜的尾巴當作畫筆，可以放下及抬起。<br />
本範例為二維空間，使用 OpenGL 搭配 C++ 實做。</p>
<p><strong>程式功能介紹：</strong><br />
1、由 turtle.txt 檔案讀入作圖指令。<br />
2、INIT - 設定海龜初始位置。(x 軸, y 軸, 龜頭角度)<br />
3、PEN - 設定尾巴狀態。(0 抬起 / 1放下)<br />
4、FW - 海龜向前移動。(移動長度)<br />
5、RIGHT - 海龜右轉角度。(角度)<br />
6、LEFT - 海龜左轉角度。(角度)</p>
<pre title="code" class="cpp">

#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;cstring&gt;
#include &lt;cmath&gt;
#include &lt;GL/glut.h&gt;
using namespace std;

const GLfloat PI = 3.141593;

class Turtle {
private:
    bool penStatus, a;
    GLfloat x1, y1, x2, y2; //座標
    GLfloat cAngle; //角度
public:
    Turtle() //constractor
    {
        penStatus = 0;
        x1 = y1 = x2 = y2 = 0.0;
        cAngle = 0.0;
        a = 0;
    }

    /* 設定海龜位置 */
    void InitPoint(GLfloat x, GLfloat y, GLfloat angle)
    {
        x1 = x; y1 = y; cAngle = angle; a = 1;
        if (penStatus) //如果 pen down 應該畫出一點
        {
            glBegin(GL_POINTS);
                glVertex2f(x, y);
            glEnd();
        }
    }
    /* 海龜向前移動 */
    void forward(GLfloat L)
    {
        x2 = x1 + L * cos(cAngle*PI/180);
        y2 = y1 + L * sin(cAngle*PI/180);

        if (penStatus)
        {
            glBegin(GL_LINES);
                glVertex2f(x1, y1);
                glVertex2f(x2, y2);
            glEnd();
        }

        x1 = x2; y1 = y2;
    }
    /* 海龜右轉角度 */
    void right(GLfloat angle)
    {
        cAngle = (a) ? cAngle - angle : angle;
        a = 1;
    }
    /* 海龜左轉角度 */
    void left(GLfloat angle)
    {
        cAngle = (a) ? cAngle + angle : angle;
        a = 1;
    }
    /* 設定畫筆狀態(0 up/1 down) */
    void setPen(bool value)
    {
        penStatus = value;
		if (value) //pen down 畫出一點
		{
			glBegin(GL_POINTS);
				glVertex2f(x1, y1);
			glEnd();
		}
    }

};

void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);  /*clear the window */

    char cmd[10];
    float x, y, angle;
    bool p;
    ifstream fp(&quot;turtle.txt&quot;);
    Turtle t;

    while (!fp.eof())
    {
        fp &gt;&gt; cmd;
        if (!strcmp(cmd, &quot;INIT&quot;)) {
            fp &gt;&gt; x &gt;&gt; y &gt;&gt; angle;
            t.InitPoint(x, y, angle);
        } else if (!strcmp(cmd, &quot;FW&quot;)) {
            fp &gt;&gt; x;
            t.forward(x);
        } else if (!strcmp(cmd, &quot;RIGHT&quot;)) {
            fp &gt;&gt; x;
            t.right(x);
        } else if (!strcmp(cmd, &quot;LEFT&quot;)) {
            fp &gt;&gt; x;
            t.left(x);
        } else if (!strcmp(cmd, &quot;PEN&quot;)) {
            fp &gt;&gt; p;
            t.setPen(p);
        }
    }

    glFlush(); /* clear buffers */
}

int main(int argc, char** argv)
{

/* Standard GLUT initialization */
    glutInit(&amp;argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); /* default, not needed */
    glutInitWindowSize(500, 500); /* 500 x 500 pixel window */
    glutInitWindowPosition(0, 0); /* place window top left on display */
    glutCreateWindow(&quot;Turtle Graphics&quot;); /* window title */
    glutDisplayFunc(display); /* display callback invoked when window opened */

/* attributes */
    glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */
    glColor3f(1.0, 0.0, 0.0); /* draw in red */
/* set up viewing */
/* 500 x 500 window with origin lower left */
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, 500.0, 0.0, 500.0);
    glMatrixMode(GL_MODELVIEW);

    glutMainLoop(); /* enter event loop */

    return 0;
}
</pre>
<p><a href="http://blog.linym.net/wp-content/uploads/2007/02/turtle.txt" title="turtle.txt">turtle.txt</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/116/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>[OOP] - 第一章作業­</title>
		<link>http://blog.linym.net/archives/80</link>
		<comments>http://blog.linym.net/archives/80#comments</comments>
		<pubDate>Fri, 17 Mar 2006 14:10:35 +0000</pubDate>
		<dc:creator>lym520</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[c lang]]></category>

		<guid isPermaLink="false">http://lym.fyman.idv.tw/blog/archives/80</guid>
		<description><![CDATA[功能說明： 輸入長及寬 => 10 7 輸入邊框及填充字元 => C + 執行結果： CCCCCCCCCC C++++++++C C++++++++C C++++++++C C++++++++C C++++++++C CCCCCCCCCC 程式實作： #include &#60;iostream&#62; #include &#60;iomanip&#62; using namespace std; int main() { int width, height; char border, inner; cout &#60;&#60; &#34;Enter Width and Height =&#62; &#34;; cin &#62;&#62; width &#62;&#62; height; cout &#60;&#60; &#34;Enter Border and Inner character =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>功能說明：</p>
<blockquote><p>輸入長及寬 => 10 7<br />
輸入邊框及填充字元 => C +<br />
執行結果：<br />
CCCCCCCCCC<br />
C++++++++C<br />
C++++++++C<br />
C++++++++C<br />
C++++++++C<br />
C++++++++C<br />
CCCCCCCCCC</p></blockquote>
<p>程式實作：</p>
<pre title="code" class="cpp">

#include &lt;iostream&gt;
#include &lt;iomanip&gt;
using namespace std; 

int main()
{
    int width, height;
    char border, inner; 

    cout &lt;&lt; &quot;Enter Width and Height =&gt; &quot;;
    cin &gt;&gt; width &gt;&gt; height;
    cout &lt;&lt; &quot;Enter Border and Inner character =&gt; &quot;;
    cin &gt;&gt; border &gt;&gt; inner;
    for (int i=1; i&lt;=height; i++)
    {
        if (i==1 || i==height)
            cout &lt;&lt; setw(width) &lt;&lt; setfill(border) &lt;&lt; border &lt;&lt; endl;
        else
            cout &lt;&lt; border &lt;&lt; setw(width-1) &lt;&lt; setfill(inner) &lt;&lt; border &lt;&lt; endl;
    }
    system(&quot;PAUSE&quot;);
    return 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.linym.net/archives/80/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

