在线时间5 小时
UID414366
ST金币0
蝴蝶豆0
注册时间2013-1-23
初级会员
- 最后登录
- 1970-1-1
|
a0a.1 0b0c
#include
#include
#include
#include "cfg.h"
const char space_tbl[4][6] = {" ", " ", " ", " "};
int main(void)
{
FILE *fp;
#ifdef USE_DEBUG
FILE *logfile;
#endif
double tbl[LENGTH];
char str[6];
unsigned char num;
unsigned char cnt;
unsigned char space_cnt;
unsigned long j;
if (LENGTH >= 10000)
{
space_cnt = 5;
}
else
{
if (LENGTH >= 1000)
{
space_cnt = 4;
}
else
{
space_cnt = 3;
}
}
#ifdef USE_DEBUG
// printf("space_cnt = %d\r\n", space_cnt);
logfile = fopen("log.txt", "w+");
#endif
for(j = 0; j < LENGTH; j++)
{
tbl[j] = PRECISION * sin((j * 2 * PI) / LENGTH);
tbl[j] += OFFSET;
}
fp = fopen("sin.txt", "w+");
cnt = 0;
for (j = 0; j < LENGTH; j++)
{
num = sprintf(str, "%d, ", (short)(tbl[j] + 0.5));
#ifdef USE_DEBUG
fprintf(logfile, "cnt %d: %d\r", j, num);
#endif
if (space_cnt > num - 2)
{
fwrite(space_tbl[space_cnt + 2 - num], 1, space_cnt + 2 - num, fp);
}
fwrite(str, 1, num, fp);
cnt ++;
if (cnt == 16)
{
cnt = 0;
fwrite("\r", 1, 1, fp);
}
}
fclose(fp);
#ifdef USE_DEBUG
fclose(logfile);
#endif
Sleep(3000);
return 0;
}
这是正弦波形 数组生成程序 生成有2百多个数组 我想问下修改哪里可以改变 输出数组的个数 |
|