易截截图软件、单文件、免安装、纯绿色、仅160KB

在线等linux下用C读写文件的例子

小弟要实现一个在文件夹里读出.txt文档的代码
然后读出来的存到另一个.txt文档里去
怎么实现呢。在网上去查了些。但是不太理解有些函数的意思
希望有人写个简单的例子并明解一下
跟windows下一样,fopen,fgets/fputs,fclose

帮我随便写个简单的行吗


而open是linux提供的系统调用,直接操作文件描述符。

http://blog.21ic.com/user1/5782/archives/2009/59848.html

linux也能用fopen,fread,fwrite,fclose等标准c的io函数。
linux也有自己的系统调用,open,read,write,close.
用标准c的简单,如果你不会系统调用的话,其实都很简单的。

windows下面的我也不怎么会用,谁能有个不报错的例子。

写个大概过程: 
    int  fd_1,fd_2;
    if ((fd_1 = open(input_file, O_RDONLY)) < 0) {
          fprintf(stderr,"Cannot open input file %s: %s\n",
                  input_file, strerror(errno));
          exit(1);
      }
    if ((fd_2 = open(ouput_file, O_WRONLY)) < 0) {
          fprintf(stderr,"Cannot open ouput file %s: %s\n",
                  input_file, strerror(errno));
          exit(1);
      }
      i = 0;
    &nbs


相关问答:

C 程序问题 (二) - C/C++ / C语言

问一下:
#include <stdio.h>
int main()
{
  char x, y, z;
  int i;
  int a[16];
  for(i=0; i<=16; i++)
  {
  a[i] = 0;
  ......

linux环境下gethostbyname函数问题 - C/C++ / C语言

写了个测试程序如下
   
  struct hostent *hp; 
char AlarmDevIP[20];  
  int x2;

hp = gethostbyname("www.google.com");
if (hp)
{ ......

刚学C,用C实现编码 - C/C++ / C语言

#include"stdio.h"
#include"stdlib.h"
void ContrTwo(char i)
{
char str1[8];
itoa(i,str1,2);
printf("%s",str1);
}
unsigned char leftRot(char str,int i);
unsign ......

向高手请教fortran 调用C 的问题

我现在要些一个fortran调用C接口的问题,但是不知道 C语言里面分配的指针怎么付给fortran,又不能在fortran立马先分配好,业务上不允许。
我写了个测试的例子。但是不行。
test.c
#include <stdio.h>
#incl ......

linux下C语言开发oracle的问题。

两个文件1.PC,1.inc
1.PC有操作oracle数据库的 ,1.inc也有操作oracle数据库 
在其他数据中如informix 中$include 1.inc就可以使用了
在ORACLE数据库重 $include 1.inc不可用 EXEC SQL include 1.inc也不可 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号