c语言从stdin读入

news/2025/3/15 5:00:24/

代码

#include<stdio.h>
#include<stdlib.h>int
main(int argc, char* argv[])
{char * line = NULL;size_t len = 0;ssize_t read_len;while ((read_len=getline(&line, &len, stdin)) != -1) {   if (read_len > 0 && line[read_len-1] == '\n'){   line[read_len-1] = '\0';read_len -= 1;  }   printf("%s\n", line);}   return 0;
}

参考

https://blog.csdn.net/lichengyu/article/details/41621099


http://www.ppmy.cn/news/603909.html

相关文章

go坑合集

//创建结构体 type cat struct {Name stringAge intColor stringMark [2]intMmap map[string]string } //实例 func main(){var cat1 catcat1.Color "yellow"cat1.Age 2cat1.Name "123"//对map、切片等引用类型需要先makecat1.Mmap make(map[string]st…

c语言使用指定字符串替换特定的子串

前言 当前程序是在linux环境下执行的 代码 #include<stdio.h> #include<stdlib.h> #include<string.h>#define MAX_UTF8_RES_LEN 1024int replace_all(char* str, size_t strLen, const char* d, const char* s) {char* pos 0;char* prv 0;char temp[MA…

2019秋招面试常考题目

自然语言处理 tf-idf的公式编辑距离的代码和思想新词发现的公式和原理 EMI(w)∑j0n[log(nw/N∏i1t(nwi−nwsf)/N)]EMI(w)\sum_{j0}^{n}\left [ log(\frac{ n_{w}/N }{\prod_{i1}^{t}( n_{w_{i}} - n_{w} s_f ) / N}) \right ]EMI(w)∑j0n​[log(∏i1t​(nwi​​−nw​sf​)/N…

使用python建立简单的树机构

代码 import sysclass TreeNode:def __init__(self, x):self.val xself.left Noneself.right Noneclass Solution:def preorderTraversal(self, root):""":type root: TreeNode:rtype: List[int]"""ret []stack [root]while stack:node s…

python内置库之学习ctypes库(一)

ctypes库踩坑日记11.引言&#xff08;这里是讲的windows下调用的方式&#xff09;2.结构体3.联合体(共用体)和上面结构体用法类似,只不过这里继承的是Union类4.进阶用法5.接受返回的值6.数据类型1.引言&#xff08;这里是讲的windows下调用的方式&#xff09; 直接上代码 代码…

由动态规划计算编辑距离引发的思考

简单介绍 编辑距离算法&#xff1a; https://www.cnblogs.com/BlackStorm/p/5400809.html https://wizardforcel.gitbooks.io/the-art-of-programming-by-july/content/05.02.html https://www.dreamxu.com/books/dsa/dp/edit-distance.html 详细 c语言实现 #include <…

前端Vue学习之路(一)-初识Vue

Vue学习之路 &#xff08;一&#xff09;1.引言2.更换npm国内镜像源3.用npm下载Vue4.Vue全家桶5.使用命令创建项目5.推荐插件6.推荐网站7.学习扩展1.引言 先安装node.js环境,方便用里面的npm &#xff0c;默认安装就行,安装之后可以在cmd命令黑窗输出 npm -V查看是否存在,顺便…

python实现二叉树的重建1 之由前序遍历和中序遍历重建

前言 此题是关于树的面试题目的常见题型&#xff0c;题目的含义很清晰&#xff0c;这个就不用多说了 解法 关于这道题的解法有很多不同的样式&#xff0c;通用的解法是这样的&#xff1a; 假如现在我们有如下两个遍历的情况 preorder: [1, 2, 4, 5, 3, 6] inorder: [4, 2,…