[DEMO] 循环写文件

超过1G则回头写

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>

struct timespec interval = {0,10};
char *a = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
char *c = "qwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiopqwertyuiop";

int main(int argc,char** agrv)
{
	long offset = 0;
	constexpr long oneGB = 1024*1024*1024;
	
	FILE* f = fopen("./loopwrite_test","wb+");
	
	while(1){
		offset = ftell(f);
		if(offset>=oneGB){
			rewind(f);
			a = c;
		}
		fwrite(a,100,1,f);
		fflush(f);
		//nanosleep(&interval,NULL);
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
STM32单片机读24位ADC_AD7190称重模块带液晶显示例程DEMO源码文件,可做为你的学习设计参考。 int main(void) { uint32_t lcdid; float data_temp; int32_t weight_count; uint8_t cali_flag=0; char str[50]; /* 复位所有外设,初始化Flash接口和系统滴答定时器 */ HAL_Init(); /* 配置系统时钟 */ SystemClock_Config(); /* 初始化串口并配置串口中断优先级 */ MX_DEBUG_USART_Init(); KEY_GPIO_Init(); /* 初始化3.5寸TFT液晶模组,一般优先于调试串口初始化 */ lcdid=BSP_LCD_Init(); /* 调用格式化输出函数打印输出数据 */ printf("LCD ID=0x%08X\n",lcdid); LCD_Clear(0,0,LCD_DEFAULT_WIDTH,LCD_DEFAULT_HEIGTH,BLACK); HAL_Delay(1000); /* 开背光 */ LCD_BK_ON(); if(AD7190_Init()==0) { printf("获取不到 AD7190 !\n"); while(1) { HAL_Delay(1000); if(AD7190_Init()) break; } } printf("检测到 AD7190 !\n"); weight_ad7190_conf(); HAL_Delay(500); weight_Zero_Data = weight_ad7190_ReadAvg(6); printf("zero:%d\n",weight_Zero_Data); /* 无限循环 */ while (1) { weight_count=weight_ad7190_ReadAvg(6); data_temp=weight_count-weight_Zero_Data; weight=data_temp*1000/weight_proportion; printf("重量:0x%5X->%f\n",weight_count,weight); sprintf(str,"0x%5X",weight_count); LCD_DispString_EN(190,80,str,BLACK,RED,USE_FONT_24); sprintf(str,"%0.2fg",weight); LCD_Clear(140,100,300,64,BLACK); LCD_DispString_EN(140,100,str,BLACK,YELLOW,USE_FONT_64); HAL_Delay(100); if(KEY1_StateRead()==KEY_DOWN) // 清零 { weight_Zero_Data = weight_ad7190_ReadAvg(6); printf("zero:%d\n",weight_Zero_Data); cali_flag=1; } if(KEY2_StateRead()==KEY_DOWN) // 校准:必须先按“清零”键,然后把20g砝码放在称上,按下校准键 { if(cali_flag) { weight_count = weight_ad7190_ReadAvg(6); weight_proportion=(weight_count-weight_Zero_Data)*1000/100; printf("weight_proportion:%d\n",weight_proportion); } cali_flag=0; } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值