[英]fgets function doesn't work
当我编写以下代码时。 腻子会打印文本,但我不能在..以下输入任何内容
例如 :
首先,他会进行printf
->您是谁?
然后我在一个fgets
上通常不输入任何内容的地方进行操作。
最后他再说printf
; 很高兴见到你 ...
int main(void)
{
/* USER CODE END 1 */
/* MCU Configuration----------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_I2C1_Init();
MX_USART2_UART_Init();
/* USER CODE BEGIN 2 */
char name[10];
printf("Who are you? \n");
fgets(name,10,stdin);
printf("Good to meet you, %s.\n",name);
return(0);
}
谁能帮我 ? 谢谢 !
您已覆盖源代码中fput的fputs
。 因此,您的链接器不需要查找该函数的库实现。 通过fputc
的实现,您已将stdio-output-path连接到UART发送器。
您需要定义相应的输入路径。 这可以通过实现fgetc函数来完成。 这样库函数fgets
可以调用您的函数,轮询UART接收器。
嵌入式环境中stdio的默认实现高度依赖于供应商。 可以连接到
因此,您有责任正确实现该连接。 这可能比fputc
实现更复杂,因为您必须检查调用时UART是否接收到数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.