易截截图软件、单文件、免安装、纯绿色、仅160KB

C发声程序

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <math.h>
#include <conio.h>
typedef struct {
      short int pitch;
      short int duration;
} NOTE;
NOTE notes[] = {{14, 500}, {16, 500}, {12, 500}, {0, 500}, {7, 1000}};
void setfreq(int hz)
{
       hz = 1193180 / hz;      // clocked at 1.19MHz
       _outp(0x43, 0xb6);      // timer 2, square wave
       _outp(0x42, hz);
       _outp(0x42, hz >> 8);
}
void playnote(NOTE note)
{
      _outp(0x61, _inp(0x61) | 0x03);   // start speaker going
      setfreq((int)(400 * pow(2, note.pitch / 12.0)));
      Sleep(note.duration);
      _outp(0x61, _inp(0x61) & ~0x03);  // stop that racket!
}
int main(int argc, char* argv[])
{
     int i;
     HANDLE h;
     h = CreateFile("\\\\.\\giveio", GENERIC_READ, 0, NULL,
     OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
     if(h == INVALID_HANDLE_VALUE)
     {
           printf("Couldn't access giveio device\n");
           return -1;
     }
     for(i=0; i < sizeof(notes)/sizeof(int); ++i)
           playnote(notes[i]);
     CloseHandle(h);
     return 0;
}
有几点需要注意:
1,\\\\.\\giveio是打开的设备,由于是用\\转义表示\,所以上述其实是表示\\ . \
2,这种底层的编程很少。以上_outp访问的是底层寄存器,功能如注


相关文档:

C、C++和C#的不同之处

C是面向过程的程序设计,程序=数据结构+算法 [最原始,但编个程确实不易]
C++是面向对象的程序设计,程序=多个类+消息(类=数据结+算法)[比较容易上手]
C# 是纯面向对象的语言[更加比较容易上手]
VC/VC++/VC# 只是用来开发C/C++/C#应用程序的软件中的一种。
......

C/C++ 内置类型的数值范围

Data   Type   Ranges  
  C/C++   recognizes   the   types   shown   in   the   table   below.  
   
  Type   Name   Bytes   Other   Names   Range   of   Values    
&nb ......

C与C++风格字符串

C风格字符串:对字符串进行操作的 C 函数定义在头文件<cstring>中;
     1. 字符串定义:char* result;
     2. 字符串的最后一个字符是null字符('\0'),可以通过这个字符确定字符串的结尾。
     3. strlen()返回的是字符串的大小;因此, ......

在Linux C编程中使用Unicode和UTF 8

目前各种Linux发行版都支持UTF-8编码,当前系统的语言和字符编码设置保存在一些环境变量中,可以通过locale命令查看:
$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPE ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号