c语言克隆
Ⅰ c语言把一个字符串复制到另一个字符串
用char指针复制字符串用while循环:
#include<stdio.h>
int main()
{ char s[300],s1[300],*p=s,*q=s1;
gets(s);
while(*q++=*p++);
puts(s1);
return 0;
}
=================
用库函数:
#include<stdio.h>
#include<string.h>
int main()
{ char s[300],s1[300];
gets(s);
strcpy(s1,s);
puts(s1);
return 0;
}
Ⅱ C语言中如何复制数组的内容
C语言中复制数组的内容源代码如下:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE 10
void show_array(const int ar[], int n);
int main()
{
int values[SIZE] = {1,2,3,4,5,6,7,8,9,10};
int target[SIZE];
double curious[SIZE / 2] =
{2.0, 2.0e5, 2.0e10, 2.0e20, 5.0e30};
puts("memcpy() used:");
puts("values (original data): ");
show_array(values, SIZE);
memcpy(target, values, SIZE * sizeof(int));
puts("target ( of values):");
show_array(target, SIZE);
puts("
Using memmove() with overlapping ranges:");
memmove(values + 2, values, 5 * sizeof(int));
puts("values -- elements 0-5 copied to 2-7:");
show_array(values, SIZE);
puts("
Using memcpy() to double to int:");
memcpy(target, curious, (SIZE / 2) * sizeof(double));
puts("target -- 5 doubles into 10 int positions:");
show_array(target, SIZE/2);
show_array(target + 5, SIZE/2);
system("pause");
return 0;
}
void show_array(const int ar[], int n)
{
int i;
for (i = 0; i < n; i++)
printf("%d ", ar[i]);
putchar('
');
}
(2)c语言克隆扩展阅读
1、C语言编程中,将常用的操作封装成函数进行调用,可以大大简化程序的编写,而且在代码的维护性及可读性方面也提供了便利。
2、不同地方需要对处理后的数组内容多次进行显示,并且很多情况下并非显示数组里面的全部内容,而仅仅是想观察数组中的部分数据内容,若每次显示时都用printf函数写的话,可以写一个自定义的通用函数,用来根据需要显示数组中的内容。
Ⅲ C语言如何将一个源程序的内容复制到另一个文本文件
找到源程序文件,
在文件上右单击鼠标,选择 复制
在空白处右单击,选择 粘贴
然后把生成的新文件改名xx.txt即可。
Ⅳ 如何用c语言将文件复制到自己想要的文件夹
C语言里的system("");函数可以执行命令行的几乎所有指令,把命令行输入的内容作为参数传入即可。复制文件的话 应该是: 源文件 目的路径。
例如命令行里的 c:\test.txt d:\text.txt,
也就是C语言里的:system(" c:\test.txt d:\text.txt");
或者这样
char c[50] = " c:\test.txt d:\text.txt";
system(c);
Ⅳ C语言能不能复制一个文件到另一个地方注意:不只是txt文本,包括所有文件,如应用程序
可以用api
BOOL CopyFile(LPCTSTR lpExistingFileName,LPCTSTR lpNewFileName,BOOL bFailIfExists );
lpExistingFileName String,源文件名
lpNewFileName String,目标文件名
bFailIfExists Long,如果设为TRUE(非零),那么一旦目标文件已经存在,则函数调用会失败。如果为FALSE,若目标文件已经存在择目标文件将会被改写
使用这个api要包含头文件windows.h
比如你想复制D盘下的ttt.exe到E盘 就这样
#include<windows.h>
intmain()
{
CopyFile("D:\ttt.exe","E:\ttt.exe",TRUE);
return0;
}
Ⅵ C语言中怎样将两个文件中内容复制到一个新的文件中
1、打开文件A,B,C
2、读取A的内容,写入C
3、读取B的内容,写入C
4、关闭文件A,B,C
Ⅶ c语言怎么复制文件
BOOL
CopyFile(LPCTSTR
lpExistingFileName,LPCTSTR
lpNewFileName,BOOL
bFailIfExists
);
说明
复制文件。与vb的file命令相似
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数
类型及说明
lpExistingFileName
String,源文件名
lpNewFileName
String,目标文件名
bFailIfExists
Long,如果设为TRUE(非零),那么一旦目标文件已经存在,则函数调用会失败。否则目标文件被改写
Ⅷ C语言编程 将一个文件复制为另一个文件
#include
int
main()
{
FILE
*one,
*two;
one
=
fopen("sfile.txt",
"r");
two
=
fopen("tfile.txt",
"w");
char
c;
while((c=fgetc(one))!=EOF)
fputc(c,two);
fflush(two);
fclose(one);
fclose(two);
return
0;
}
一个最简单的文件复制函数,功能很有限,要求源文件和目标文件在同一个目录下。。。。。。
Ⅸ 怎样用C语言将文件复制另外的文件夹
有两种方式可以实现复制:
一、自行编写函数,实现复制。
算法流程如下:
1
以读的方式打开源文件,以写的方式打开目标文件;
2
每次读一个字节,并写到目标文件中,直到达到文件结尾为止;
3
关闭两个文件。
二、调用系统命令。
stdlib.h中的system函数,可以执行系统命令行支持的命令。
int
system(char
*cmd);
调用时就是执行cmd中的指令。
1
对于windows,就是执行dos命令,可以调用
system("
/Y
src_file
target_dir");
其中src_file为源文件,而target_dir就是目标文件夹。
2
对于Linux,需要执行shell命令cp,如下
system("cp
src_file
target_dir");
Ⅹ 如何用C语言复制任意格式的文件(不用系统提供的函数的那种)
这是个比较简单的程序,效率比较低(一个字节一个字节地复制)但能完成要求.
#include<stdio.h>
void main() { FILE *fp,*tp; unsigned char x;
char sfnm[]={ "c:\\data\\test.dat" }; // 写入源文件名,当前文件为c:\data\test.dat
char tfnm[]={ "c:\\data\\test1.dat" }; // 写入目的文件名,当前文件为c:\data\test1.dat
if ( fp=fopen(sfnm,"rb") ) {
if ( tp=fopen(tfnm,"wb+") {
while ( !feof(fp) ) { fread(&x,1,1,fp); fwrite(&x,1,1,tp); }
fclose(tp);
} else printf("无法打开目的文件%s\n",tfnm);
fclose(fp);
} else printf("无法打开源文件%s\n",sfnm);
}