![]() | ภาษาซี (C Computer Language) | ![]() |
ผู้สอน : อ.อติชาต หาญชาญชัย ผู้สอน : อ.บุรินทร์ รุจจนพันธุ์ MSDN of C++ : Output File Stream function Download Site : Borland C++ 5.5 ! . To Install BCC55 #1, #2, #3 # Old Compiler : Turbo C++ 3.0 . . # แนวคิดการสอนเขียนโปรแกรม |
ความหมายของภาษาซี
#include <stdio.h> void main() { } |
|
Visual Studio 8
http://msdn.microsoft.com/en-us/library/59zy697d(VS.80).aspx
start : Visual Studio 2005 Command Prompt
DOS> cl cl0101.cpp
DOS> cl /clr cl0101.cpp
- ถ้า #include <iostream> ต้องใช้ /clr
- /clr ทำให้มีการเรียกใช้ Incremental Linker
- ให้ใช้ getchar() แทน getch()
- ใช้ getchar() จะต้อง #include <stdio.h>
- ใช้ system("PAUSE") จะต้อง #include <stdlib.h>
- ถ้าใช้ cout ต้อง
#include <iostream> และ using namespace std; // for cout
จึงจะใช้ cout << "a" << endl;
แต่ถ้า #include |
| ตัวแปลภาษา (Compiler) BCC 5.5.1
+ http://www.cplusplus.com/reference/clibrary/cstdlib/malloc/
| Download Site : Borland C++ 5.5 9 MB ! . Configuration สำหรับ Compile ใน Editplus เมื่อใช้ BCC 5.5.1 - ให้กำหนด Command : C:\Borland\BCC55\Bin\bcc32.exe - ให้กำหนด Argument : -IC:\Borland\BCC55\Include -LC:\Borland\BCC55\Lib -n$(FileDir) $(FilePath) - ให้กำหนด Initial directory : C:\Borland\BCC55\Bin - ให้ click ที่ Capture Output Configuration สำหรับ Run ใน Editplus เมื่อใช้ BCC 5.5.1 (กรณีไม่รับค่าจากแป้นพิมพ์) - ให้กำหนด Command : $(FileNameNoExt) - ให้กำหนด Initial directory : $(FileDir) - ให้ click ที่ Capture Output มีปัญหาเรื่องการ compile หรือ run - เพื่อนท่านหนึ่งโทรมาถามว่า run ใน Command line ไม่มีปัญหา แต่พบปัญหาการหยุดรับค่าจากแป้นพิมพ์ เมื่อใช้ EditPlus - ให้กำหนด Command เป็น "c:\windows\system32\cmd.exe" "/k" - ให้กำหนด Argument เป็น $(FileNameNoExt) หรือ E:\KEEPSRC\$(FileNameNoExt) - ไม่ click ที่ Capture Output เพื่อไม่ให้ run ใน Output window - ถ้าต้องการแปลผ่าน Command Line ควรสร้างแฟ้ม bcc32.cfg ในห้อง bin แล้วเพิ่ม 2 บรรทัดนี้ลงไป
|
ตัวแปลภาษา (Compiler) TurboC 3.0|
| Download Site : TurboC 3.0 3 MB วิธีแก้ปัญหา |
| บทเรียนพิเศษ (Extra Lesson) |
โปรแกรมค้นหาตัวอักษรใน string
หัวหน้าผมใช้โปรแกรมลักษณะนี้ออกข้อสอบ จึงต้องทดสอบโปรแกรม เตรียมสอนนักศึกษา
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
main(void) {
clrscr();
char string[6];
char *ptr, z=z;
strcpy(string, "abcdef");
ptr = strchr(string, z);
if (strlen(ptr) == 0) cout << "not found z";
ptr = strchr(string, c);
if (strlen(ptr) > 0) cout << "found c";
getch();
}
|
|
ศึกษาเรื่อง date เพราะมีนักศึกษาคนหนึ่งโทรมาถาม
พบตัวอย่างที่ http://www.cs.duke.edu/~ola/ap/dates/ |
นำตัวแปร myMonth myDate และ myYear ไปใช้ต่อได้
#include <time.h>
#include <stdio.h>
#include <conio.h>
void main() {
clrscr();
static struct tm timeHolder;
static struct tm *date = &timeHolder;
time_t tloc;
time(&tloc);
date = localtime(&tloc);
int myMonth = date->tm_mon + 1;
int myDay = date->tm_mday;
int myYear = date->tm_year + 1900;
printf("%d%d%d",myMonth,myDay,myYear);
getch(); // 9122007 (9 Dec 2007)
}
|
อีเมลจากเพื่อนชาวไทย ที่ให้คำแนะนำทีมงาน
1. คุณศร [sorn_kkc@hotmail.com] : ส่งโปรแกรมนี้มาให้ผมตอบคำถาม คำถามของคุณศร : เขียนโปรแกรมส่งข้อมูลผ่าน port printer โดยควบคุมหลอด LED ปรากฎว่าไม่ได้ผลตามโปรแกรมที่เขียน ผมก็ไม่รู้ จึงค้นคว้าเพิ่มเติม และไปเข้าใจที่ หนังสือภาษาซี ของ ดอนสัน ปงผาบ อ.คณะเทคโนโลยีอุตสาหกรรม ม.ราชภัฏลำปาง (donson@lpru.ac.th) จึงเข้าใจว่า LED คืออะไร .. ผลการทดสอบต่อวงจรครั้งแรกในชีวิต ก็ได้มา 7 ภาพดังที่เห็น พร้อมแผลพุพองที่นิ้วกลางซ้ายอีกแผล
http://www.etteam.com/downloadf.html (มี compiler manual และ code แก้ปัญหา) http://www.beyondlogic.org/spp/parallel.htm (Have detail of pin number) http://www.machinegrid.com/content/view/30/84/ (แสดงการประยุกต์กับมอเตอร์) http://www.nelnickrobotics.com/printer_port.html (ภาพวงจรการเชื่อมต่ออุปกรณ์) http://my.tele2.ee/chipmcu/ing/prog705j.htm (อ่าน e-prom จาก printer port) http://www.xmlblaster.org/xmlBlaster/doc/doxygen/cpp/html/classorg_1_1xmlBlaster_1_1test_1_1TestQueue.html http://www.dreamincode.net/forums/showtopic49439.htm (Data Structure)
ตัวอย่างภาษาซี กับส่งข้อมูลออกทาง Printer Port ที่ http://www.thaiall.com/printer | |||||||||