#include<stdio.h>
#include<string.h>
int main(){
const char* in_file = "input_file_name";
const char* out_file = "output_file_name";
FILE *p_in = fopen(in_file, "r");
if(!p_in){
printf("open file %s failed!!!", in_file);
return -1;
}
FILE *p_out = fopen(out_file, "w");
if(!p_in){
printf("open file %s failed!!!", out_file);
if(!p_in){
fclose(p_in);
}
return -1;
}
char buf[2048];
//按行读取文件内容
while(fgets(buf, sizeof(buf), p_in) != NULL) {
//写入到文件
fwrite(buf, sizeof(char), strlen(buf), p_out);
}
fclose(p_in);
fclose(p_out);
return 0;
}
#include<stdio.h>
int main(){
char buf[2048];
gets(buf);
printf("%s\n", buf);
return 0;
}
/// scanf 遇到空格等字符会结束
/// gets 遇到换行符结束
<?php
$filename = "input_file_name";
$fp = fopen($filename, "r");
if(!$fp){
echo "open file $filename failed\n";
exit(1);
}
else{
while(!feof($fp)){
//fgets(file,length) 不指定长度默认为1024字节
$buf = fgets($fp);
$buf = trim($buf);
if(empty($buf)){
continue;
}
else{
echo $buf."\n";
}
}
fclose($fp);
}
?>
<?php
$fp = fopen("/dev/stdin", "r");
while($input = fgets($fp, 10000)){
$input = trim($input);
echo $input."\n";
}
fclose($fp);
?>
#coding=utf-8 # 如果要在python2的py文件里面写中文,则必须要添加一行声明文件编码的注释,否则python2会默认使用ASCII编码。 # 编码申明,写在第一行就好 import sys input = sys.stdin for i in input: #i表示当前的输入行 i = i.strip() print i input.close()
#!/bin/bash
#读取文件, 则直接使用文件名; 读取控制台, 则使用/dev/stdin
while read line
do
echo ${line}
done < filename
#!/bin/bash
while read line
do
echo ${line}
done < /dev/stdin
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有