read a line with arbitrary length using fgets

let me know if you found any issue via bruceadi(at)hotmail.com, thanks 微笑
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char* getline(char** pbuf, size_t* buflen, FILE* stream)
{
	if(*buflen <= 1) return NULL;	
	if(!fgets(*pbuf, *buflen, stream)) return NULL;
	size_t len;
	while(len = strlen(*pbuf), !feof(stream) &&  (*pbuf)[len - 1] != '\n')
	{
		
		char* pOld = *pbuf;
		*pbuf = (char*)realloc(*pbuf, *buflen << 1);
		if(NULL == *pbuf) 
		{
			free(pOld);
			*buflen = 0;
			return *pbuf;
		}
		fgets(*pbuf + len , *buflen + 1, stream);
		*buflen <<= 1; 
	}

	if((*pbuf)[len - 1] == '\n')
	{
		(*pbuf)[len - 1 ]= 0;
		return *pbuf;
	}

	return *pbuf;
}

int main()
{
	size_t len = 32;
	char* line = (char*)malloc(len);
	while(getline(&line, &len, stdin))
	{
		puts(line);
	}
	free(line);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Acoustoelastic guided waves refer to the phenomenon where elastic waves are generated due to the interaction between acoustic waves and the elastic properties of a material. In waveguides, such as pipes or bars, these waves can propagate along the length of the waveguide, allowing for non-destructive testing and monitoring of the material's properties. One important factor that affects the propagation of acoustoelastic waves is the prestress in the material. Prestress refers to the state of stress in a material before any external forces are applied. This can arise due to manufacturing processes, such as casting or rolling, or due to environmental factors, such as temperature changes. In waveguides with arbitrary prestress, the propagation of acoustoelastic waves can be modeled using mathematical equations that take into account the material's elastic properties, the waveguide's geometry, and the prestress state. These equations can be solved numerically to predict the behavior of the waves under different conditions. For example, if a waveguide experiences a sudden change in temperature, the prestress state may change, which can affect the propagation of acoustoelastic waves. By modeling the waveguide's behavior, engineers can predict how the waves will propagate and detect any changes in the material's properties. Overall, acoustoelastic guided waves in waveguides with arbitrary prestress have important applications in non-destructive testing and monitoring of materials in a variety of industries, including aerospace, automotive, and construction.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值