c语言发送到邮箱的函数 c++ 发送邮件

请教,如何用C语言编写一个函数。

一个函数(function)是一个可以从程序其它地方调用执行的语句块。以下是函数定义格式:

10余年的万年网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整万年建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“万年网站设计”,“万年网站推广”以来,每个客户项目都认真落实执行。

type name ( argument1, argument2, ...) statement

说明:

type 是函数返回的数据的类型

name 是函数被调用时使用的名

argument 是函数调用需要传入的参量(可以声明任意多个参量)。每个参量(argument)由一个数据类型后面跟一个标识名称组成,就像变量声明中一样(例如,int x)。参量仅在函数范围内有效,可以和函数中的其它变量一样使用, 它们使得函数在被调用时可以传入参数,不同的参数用逗号(comma)隔开.

statement 是函数的内容。它可以是一句指令,也可以是一组指令组成的语句块。如果是一组指令,则语句块必须用花括号{}括起来,这也是我们最常见到情况。其实为了使程序的格式更加统一清晰,建议在仅有一条指令的时候也使用花括号,这是一个良好的编程习惯。

示例:每一个C语言程序有且只有一个main函数,本身main就是一个函数。结合上面的格式,自己理解一下。

int main()

{

return 0;

}

C语言 send()函数理解

使用函数getsockopt获得发送缓冲区的长度。用法如下:

int sockfd;

int val;

int len;

sockfd = socket (AF_INET, SOCK_STREAM, 0);

len = sizeof (val);

getsockopt( sockfd, SOL_SOCKET, SO_SNDBUF, val, len);

printf ("sndbuf len=%d\n", val);

在32位linux系统上发送缓冲区为16K ,可以使用setsockopt()修改,会影响网络性能

加强版51单片机STC12C5A60S2用NRF24L01发送一个字节的C语言程序 邮箱wmb007@126.com

// SPI(nRF24L01) 命令定义

#define READ_REG 0x00 // 定义读寄存器命令

#define WRITE_REG 0x20 // 定义写寄存器命令

#define RD_RX_PLOAD 0x61 // 定义接收有效载荷寄存器

#define WR_TX_PLOAD 0xA0 // 定义发送有效载荷寄存器

#define FLUSH_TX 0xE1 // 定义清除发送寄存器命令

#define FLUSH_RX 0xE2 // 定义清除接收寄存器命令

#define REUSE_TX_PL 0xE3 // 定义复用发送有效载荷寄存器命令

#define NOP1 0xFF // 定义空操作,用于读取状态寄存器

// SPI(nRF24L01) registers(addresses)

#define CONFIG 0x00 // “配置寄存器”地址

#define EN_AA 0x01 // “使能自动应答寄存器”地址

#define EN_RXADDR 0x02 // “使能接收地址寄存器”地址

#define SETUP_AW 0x03 // “设置地址长度寄存器”地址

#define SETUP_RETR 0x04 // “设置自动重发寄存器”地址

#define RF_CH 0x05 // “RF(射频)频道寄存器”地址

#define RF_SETUP 0x06 // “RF(射频)设置寄存器”地址

#define STATUS_24L01 0x07 // “状态寄存器”地址

#define OBSERVE_TX 0x08 // “?寄存器”地址

#define CD 0x09 // “发现载波寄存器”地址

#define RX_ADDR_P0 0x0A // “通道0接收寄存器”地址

#define RX_ADDR_P1 0x0B // "通道1接收寄存器"地址

#define RX_ADDR_P2 0x0C // "通道2接收寄存器"地址

#define RX_ADDR_P3 0x0D // "通道3接收寄存器"地址

#define RX_ADDR_P4 0x0E // "通道4接收寄存器"地址

#define RX_ADDR_P5 0x0F // "通道5接收寄存器"地址

#define TX_ADDR 0x10 // ”发送寄存器“地址

#define RX_PW_P0 0x11 // ”通道0有效载荷(数据)长度寄存器“地址

#define RX_PW_P1 0x12 // ”通道1有效载荷长度寄存器“地址

#define RX_PW_P2 0x13 // ”通道2有效载荷长度寄存器“地址

#define RX_PW_P3 0x14 // ”通道3有效载荷长度寄存器“地址

#define RX_PW_P4 0x15 // ”通道4有效载荷长度寄存器“地址

#define RX_PW_P5 0x16 // ”通道5有效载荷长度寄存器“地址

#define FIFO_STATUS 0x17 // “FIFO状态寄存器的寄存器”地址

//**-------------------------------

#define TX_ADR_WIDTH 5 //发送地址字节数

#define RX_PLOAD_WIDTH 16 //接收数据字节数

#define TX_PLOAD_WIDTH 16 //发送数据字节数

#define MAX_CONTROL_NUMBER 2 //2 line concrol 2 relay remote control

#define NOP _nop_();

#define NOP5 NOP;NOP;NOP;NOP;NOP;

#define NOP10 NOP5;NOP5;

#define NOP20 NOP10;NOP10;

#define delay_130us() NOP20;NOP20;NOP20;NOP20;NOP20;NOP20;NOP10;

#define uchar unsigned char

#define BYTE unsigned char

sbit CE = P2^2;

sbit CSN = P2^3;

sbit SCK = P2^4 ;

sbit MOSI = P2^5;

sbit MISO = P2^6 ; //数据输入引脚

sbit IRQ_24L01= P2^7 ;//spi通讯端口定义

/**---------------------------------*/

unsigned char TX_ADDRESS[5]={

0x1,0x02,0x03,0x04,0x05

};

unsigned char RX_ADDRESS[5]={

0x01,0x02,0x03,0x04,0x05

};

/*_________________________________*/

void nRF24L01_Config(void); // 配置函数

uchar SPI_RW(uchar byte); // 写一个字节到24L01,同时读出一个字节

//uchar SPI_READ_Reg(BYTE reg); // 读出寄存器的值

uchar SPI_RW_Reg(BYTE reg, BYTE value); // 向寄存器reg写一个字节,同时返回状态字节

uchar SPI_Read_Buf(BYTE reg, BYTE *pBuf, BYTE bytes); //nRF24L01读出字节

uchar SPI_Write_Buf(BYTE reg, BYTE *pBuf, BYTE bytes); //nRF24L01写入字节

unsigned char nRF24L01_RxPacket(unsigned char* rx_buf); //nRF24L01数据接收

void nRF24L01_TxPacket(unsigned char * tx_buf); //nRF24L01数据发送

bit rec_validate_end(void); //接收数据完成后进行校正处理

void set_24L01_rec_mode(void);

//void test_24l01_irq(void); //测试nRF24L01

/*-----------------------------*

公司名称:xxxxxx

函数名称:nRF24L01数据读/写

函数功能:写一个字节到24L01,同时读出一个字节

设计时间:

设 计 者:

------------------------------*/

uchar SPI_RW(uchar byte)

{

uchar bit_ctr;

bit_ctr=0;

for(bit_ctr=0;bit_ctr8;bit_ctr++) // output 8-bit

{

MOSI = (byte 0x80); // wait output 'byte', MSB to MOSI

byte = (byte 1); // shift next bit into MSB..

SCK = 1; // Set SCK high..

//--------------------------

MISO=1;

NOP5;

///-------------------------

byte |= MISO; // read capture current MISO bit

SCK = 0; // ..then set SCK low again

}

return(byte); // return read byte

}

/*-----------------------------*

公司名称:xxxxxx

函数名称:nRF24L01数据读取

函数功能:向寄存器reg写一个字节,同时返回状态字节

设计时间:

设 计 者:

------------------------------*/

//

uchar SPI_RW_Reg(BYTE reg, BYTE value)

{

uchar status_24L01;

status_24L01 = 0;

CSN = 0; // CSN low, init SPI transaction

status_24L01 = SPI_RW(reg); // select register 选择通道

SPI_RW(value); // ..and write value to it..

CSN = 1; // CSN high again

return(status_24L01); // return nRF24L01 status byte

}

//读数据

uchar SPI_Read_Buf(BYTE reg, BYTE *pBuf, BYTE bytes)

{

uchar status_24L01,byte_ctr;

status_24L01 = 0;

byte_ctr = 0;

CSN = 0; // Set CSN low, init SPI tranaction

status_24L01 = SPI_RW(reg); // Select register to write to and read status byte

for(byte_ctr=0;byte_ctrbytes;byte_ctr++)

pBuf[byte_ctr] = SPI_RW(0); //选择信号通道?

CSN = 1;

return(status_24L01); // return nRF24L01 status byte

}

/*-----------------------------*

公司名称:xxxxxx

函数名称:nRF24L01

函数功能:写入bytes字节的数据

设计时间:

设 计 者:

------------------------------*/

uchar SPI_Write_Buf(BYTE reg, BYTE *pBuf, BYTE bytes)

{

uchar status_24L01,byte_ctr;

status_24L01=0;

byte_ctr=0;

CSN = 0;

status_24L01 = SPI_RW(reg);

for(byte_ctr=0; byte_ctrbytes; byte_ctr++) //

SPI_RW(*pBuf++); //;需要发送的数据在PBUF表格里;

//;需要发送的字节数载bytes;

//对其操作的命令在reg里

CSN = 1; // Set CSN high again

return(status_24L01); //

}

/*-----------------------------*

公司名称:xxxxxx

函数名称:nRF24L01__set_24L01_rec_mode

函数功能:写寄存器命令;并寄存器配置地址

设计时间:

设 计 者:

------------------------------*/

/*-----------------------------*

公司名称:xxxxxx

函数名称:nRF24L01 ** nRF24L01_RxPacket

函数功能:接收函数,返回1表示有数据收到,否则没有数据接受到

设计时间:

设 计 者: 测试通过

------------------------------*/

unsigned char nRF24L01_RxPacket(unsigned char* rx_buf)

{

unsigned char sta,revale=0;

sta =0;

revale=0;

// set in RX mode

SPI_RW_Reg(WRITE_REG + CONFIG, 0x0f); // Set PWR_UP bit, enable CRC(2 bytes) Prim:RX. RX_DR enabled..

CE = 1; // Set CE pin high to enable RX device

delay_130us();

sta=SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01); // read register STATUS's value

//读取nRF24L01所处于的状态

if(sta0x40) // if receive data ready (RX_DR) interrupt 如果准备接收数据则中断1;

{

CE = 0; // stand by mode

SPI_Read_Buf(RD_RX_PLOAD,rx_buf,TX_PLOAD_WIDTH);

// read receive payload from RX_FIFO buffer

//读取16个字节的数据最大32BIT

revale =1;

}

SPI_RW_Reg(WRITE_REG+STATUS_24L01,sta);// clear RX_DR or TX_DS or MAX_RT interrupt flag

return revale;

}

/*-----------------------------*

公司名称:xxxxxx

函数名称:nRF24L01

函数功能:发送函数

设计时间:

设 计 者:

------------------------------*/

void nRF24L01_TxPacket(unsigned char * tx_buf)

{

CE=0;

SPI_Write_Buf(WRITE_REG + TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH); // 发送5个地址24l01

SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH); // RX_Addr0 same as TX_Adr for Auto.Ack

SPI_Write_Buf(WR_TX_PLOAD, tx_buf, TX_PLOAD_WIDTH); // Writes data to TX payload

SPI_RW_Reg(WRITE_REG + CONFIG, 0x0e); // Set PWR_UP bit, enable CRC(2 bytes) Prim:TX. MAX_RT TX_DS enabled..

CE=1;

NOP20;

CE=0;

}

/*-----------------------------*

公司名称:xxxxxx

函数名称:nRF24L01 ** nRF24L01_Config

函数功能:配置函数

设计时间:

设 计 者:

------------------------------*/

void nRF24L01_Config(void)

{

//initial io of 24L01

CE=0; // chip enable

CSN=1; // Spi disable

SCK=0; // Spi clock line init high

CE=0;

SPI_RW_Reg(WRITE_REG + CONFIG, 0x0f); // Set PWR_UP bit, enable CRC(2 bytes) Prim:RX. RX_DR enabled..

SPI_RW_Reg(WRITE_REG + EN_AA, 0x01); //Enable auto_ack Pipe0

// SPI_RW_Reg(WRITE_REG + EN_AA, 0x00); //DISable auto_ack Pipe0

SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01); // Enable Pipe0

SPI_RW_Reg(WRITE_REG + SETUP_AW, 0x03); // Setup address width=5 bytes

SPI_RW_Reg(WRITE_REG + SETUP_RETR, 0x1a); // 500us + 86us, 10 retrans...

SPI_RW_Reg(WRITE_REG + RF_CH, 0x02); //channel 2

SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x07); // TX_PWR:0dBm, Datarate:1Mbps, LNA:HCURR

SPI_RW_Reg(WRITE_REG + RX_PW_P0, RX_PLOAD_WIDTH);

SPI_Write_Buf(WRITE_REG + TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH);

SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH);

CE=1;

}

/*------------------------------*/

bit rec_validate_end(void)

{

if(IRQ_24L01==1)return 0;

// if(nRF24L01_RxPacket(remote_buf)0x01)return (1);

else return (0);

}

void set_24L01_rec_mode(void)

{

SPI_RW_Reg(WRITE_REG + CONFIG, 0x0f); // Set PWR_UP bit, enable CRC(2 bytes) Prim:RX. RX_DR enabled..

RX_ADDRESS[0]=0XF0;

RX_ADDRESS[1]=0XF0;

RX_ADDRESS[2]=0XF0;

RX_ADDRESS[3]=0XF0;

RX_ADDRESS[4]=0XC0;

SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, RX_ADDRESS[0], TX_ADR_WIDTH);

CE = 1; // Set CE pin high to enable RX device

}

C语言中有个#include 请问这个头文件库是什么啊?谁有把它的库弄好发到我的邮箱

不是api.h

是winapi.h或者win32api.h之类

其实#include windows.h就有涵盖了api中函数使用的功能

你具体想要做什么?

用纯C语言写窗口程序么?

window-api库文件一般开发环境都会有,在其安装目录MFC里面就可以找到相关的

不明白C语言的SendMessage函数

不是等于VM_ 应该是WM_。

WM指的是WindowMessage 即windows消息。

以WM_开头的是预定义的windows消息。

windows是基于消息驱动的操作系统,当程序接收到系统发送的消息后会做出相应的响应。

例如程序向窗口发送一个 WM_PAINT消息,则窗口会重新绘制。

求C语言函数大全

函数名: abort

功 能: 异常终止一个进程

用 法: void abort(void);

程序例:

#include stdio.h

#include stdlib.h

int main(void)

{

printf("Calling abort()\n");

abort();

return 0; /* This is never reached */

}

函数名: abs

功 能: 求整数的绝对值

用 法: int abs(int i);

程序例:

#include stdio.h

#include math.h

int main(void)

{

int number = -1234;

printf("number: %d absolute value: %d\n", number, abs(number));

return 0;

}

函数名: absread, abswirte

功 能: 绝对磁盘扇区读、写数据

用 法: int absread(int drive, int nsects, int sectno, void *buffer);

int abswrite(int drive, int nsects, in tsectno, void *buffer);

程序例:

/* absread example */

#include stdio.h

#include conio.h

#include process.h

#include dos.h

int main(void)

{

int i, strt, ch_out, sector;

char buf[512];

printf("Insert a diskette into drive A and press any key\n");

getch();

sector = 0;

if (absread(0, 1, sector, buf) != 0)

{

perror("Disk problem");

exit(1);

}

printf("Read OK\n");

strt = 3;

for (i=0; i80; i++)

{

ch_out = buf[strt+i];

putchar(ch_out);

}

printf("\n");

return(0);

}

函数名: access

功 能: 确定文件的访问权限

用 法: int access(const char *filename, int amode);

程序例:

#include stdio.h

#include io.h

int file_exists(char *filename);

int main(void)

{

printf("Does NOTEXIST.FIL exist: %s\n",

file_exists("NOTEXISTS.FIL") ? "YES" : "NO");

return 0;

}

int file_exists(char *filename)

{

return (access(filename, 0) == 0);

}

函数名: acos

功 能: 反余弦函数

用 法: double acos(double x);

程序例:

#include stdio.h

#include math.h

int main(void)

{

double result;

double x = 0.5;

result = acos(x);

printf("The arc cosine of %lf is %lf\n", x, result);

return 0;

}

函数名: allocmem

功 能: 分配DOS存储段

用 法: int allocmem(unsigned size, unsigned *seg);

程序例:

#include dos.h

#include alloc.h

#include stdio.h

int main(void)

{

unsigned int size, segp;

int stat;

size = 64; /* (64 x 16) = 1024 bytes */

stat = allocmem(size, segp);

if (stat == -1)

printf("Allocated memory at segment: %x\n", segp);

else

printf("Failed: maximum number of paragraphs available is %u\n",

stat);

return 0;

}

函数名: arc

功 能: 画一弧线

用 法: void far arc(int x, int y, int stangle, int endangle, int radius);

程序例:

#include graphics.h

#include stdlib.h

#include stdio.h

#include conio.h

int main(void)

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

int midx, midy;

int stangle = 45, endangle = 135;

int radius = 100;

/* initialize graphics and local variables */

initgraph(gdriver, gmode, "");

/* read result of initialization */

errorcode = graphresult(); /* an error occurred */

if (errorcode != grOk)

{

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1); /* terminate with an error code */

}

midx = getmaxx() / 2;

midy = getmaxy() / 2;

setcolor(getmaxcolor());

/* draw arc */

arc(midx, midy, stangle, endangle, radius);

/* clean up */

getch();

closegraph();

return 0;

}

函数名: asctime

功 能: 转换日期和时间为ASCII码

用 法: char *asctime(const struct tm *tblock);

程序例:

#include stdio.h

#include string.h

#include time.h

int main(void)

{

struct tm t;

char str[80];

/* sample loading of tm structure */

t.tm_sec = 1; /* Seconds */

t.tm_min = 30; /* Minutes */

t.tm_hour = 9; /* Hour */

t.tm_mday = 22; /* Day of the Month */

t.tm_mon = 11; /* Month */

t.tm_year = 56; /* Year - does not include century */

t.tm_wday = 4; /* Day of the week */

t.tm_yday = 0; /* Does not show in asctime */

t.tm_isdst = 0; /* Is Daylight SavTime; does not show in asctime */

/* converts structure to null terminated

string */

strcpy(str, asctime(t));

printf("%s\n", str);

return 0;

}

函数名: asin

功 能: 反正弦函数

用 法: double asin(double x);

程序例:

#include stdio.h

#include math.h

int main(void)

{

double result;

double x = 0.5;

result = asin(x);

printf("The arc sin of %lf is %lf\n", x, result);

return(0);

}

函数名: assert

功 能: 测试一个条件并可能使程序终止

用 法: void assert(int test);

程序例:

#include assert.h

#include stdio.h

#include stdlib.h

struct ITEM {

int key;

int value;

};

/* add item to list, make sure list is not null */

void additem(struct ITEM *itemptr) {

assert(itemptr != NULL);

/* add item to list */

}

int main(void)

{

additem(NULL);

return 0;

}

函数名: atan

功 能: 反正切函数

用 法: double atan(double x);

程序例:

#include stdio.h

#include math.h

int main(void)

{

double result;

double x = 0.5;

result = atan(x);

printf("The arc tangent of %lf is %lf\n", x, result);

return(0);

}

函数名: atan2

功 能: 计算Y/X的反正切值

用 法: double atan2(double y, double x);

程序例:

#include stdio.h

#include math.h

int main(void)

{

double result;

double x = 90.0, y = 45.0;

result = atan2(y, x);

printf("The arc tangent ratio of %lf is %lf\n", (y / x), result);

return 0;

}

函数名: atexit

功 能: 注册终止函数

用 法: int atexit(atexit_t func);

程序例:

#include stdio.h

#include stdlib.h

void exit_fn1(void)

{

printf("Exit function #1 called\n");

}

void exit_fn2(void)

{

printf("Exit function #2 called\n");

}

int main(void)

{

/* post exit function #1 */

atexit(exit_fn1);

/* post exit function #2 */

atexit(exit_fn2);

return 0;

}

函数名: atof

功 能: 把字符串转换成浮点数

用 法: double atof(const char *nptr);

程序例:

#include stdlib.h

#include stdio.h

int main(void)

{

float f;

char *str = "12345.67";

f = atof(str);

printf("string = %s float = %f\n", str, f);

return 0;

}

函数名: atoi

功 能: 把字符串转换成长整型数

用 法: int atoi(const char *nptr);

程序例:

#include stdlib.h

#include stdio.h

int main(void)

{

int n;

char *str = "12345.67";

n = atoi(str);

printf("string = %s integer = %d\n", str, n);

return 0;

}

函数名: atol

功 能: 把字符串转换成长整型数

用 法: long atol(const char *nptr);

程序例:

#include stdlib.h

#include stdio.h

int main(void)

{

long l;

char *str = "98765432";

l = atol(lstr);

printf("string = %s integer = %ld\n", str, l);

return(0);

}


名称栏目:c语言发送到邮箱的函数 c++ 发送邮件
文章分享:http://myzitong.com/article/hghgpd.html