linux控制台显示中文
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main()
{
#ifdef _WIN32
setlocale(LC_ALL, "chs");
#else
setlocale(LC_ALL, "zh_CN.UTF-8");
#endif
wchar_t KZg[] = {0x6211, 0};
char buf[10] = {0};
wcstombs(buf,KZg,10);
printf("_%s_\n",buf);
}
wchar_t 在linux上是4个字节, 在win32上是2个字节, MinGW也是2个字节.
一般会节省空间使用utf-16.
#ifdef _WIN32
typedef wchar_t uchar;
#else
typedef unsigned short uchar; // 就不能使用string.h提供的宽字符串方法了.
#endif
linux上使用string常量只能用{}.
相关文档:
例一:发送Signaling Packet:
Signaling Command是2个Bluetooth实体之间的L2CAP层命令传输。所以得Signaling Command使用CID 0x0001.
多个Command可以在一个C-frame(control frame)中发送。
如果要直接发送Signaling Command.需要建立SOCK_RAW类型的L2CAP连接Socket。这样才有机会自己填充Command Code,Identi ......
#include <stdio.h>
#include <unistd.h>
#define FOO "foo"
int main(void)
{
if(!access(FOO, F_OK))
{
if(!unlink(FOO))
{
}
else
{
printf("remove %s failed\n", FOO);
}
}
else
{
printf("%s not existed\ ......
以前已经接触Windows下的Socket编程,最近也尝试着再linux下使用Socket编程,下面是在网上找的例子(已经测试过)
tcp_server.c:
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <stdlib.h>
# ......
Linux下C语言编程基础(Makefile)
2005-01-18 10:28:23 来自:赛迪网
假设我们有下面这样的一个程序,源代码如下:
/* main.c */
#include "mytool1.h"
#include "mytool2.h"
int main(int argc,char **argv)
{
mytool1_print("hello");
mytool2_print(&q ......