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访问的是底层寄存器,功能如注
相关文档:
二分查找的代码.
int bfind(int* a,int len,int val)
{
int m = len/2;
int l = 0;
int r = len;
while(l!=m && r!= m)
{
if(a[m] > val)
& ......
1.已知strcpy 函数的原型是:
char *strcpy(char *strDest, const char *strSrc);
其中strDest 是目的字符串,strSrc 是源字符串。不调用C++/C 的字符串库函数,请编写函数 strcpy
答案:
char *strcpy(char *strDest, const char *strSrc)
{
if ( strDest == NULL || strSrc == NULL)
return NULL ;
if ( strDest ......
char a[10];
怎么给这个数组赋值呢?
1、定义的时候直接用字符串赋值
char a[10]="hello";
注意:不能先定义再给它赋值,如char a[10]; a[10]="hello";这样是错误的!
2、对数组中字符逐个赋值
char a[10]={'h','e','l','l','o'};
3、利用strcpy
char a[10]; strcpy(a, "hello");
易错情况:
1、char a[1 ......
搞软件是有搞头的
——邹祁峰
2009年12月3日
声明:所说的只针对C、C++、.NET专业的同学,对其他专业也许没有参考价值!
[推荐给大三的学弟学妹们]
【欢迎各位朋友补充】
对我个人而言,大学毕业找工作算是画上了一个许多人羡慕,但我自己仍感遗憾的句号。找工作期间 ......