#include <stdio.h> /* standard input/output routines. */
#include <time.h>
#define MAX_LINE_LEN 1000 /* maximal line length supported. */
void main(int argc, char* argv[])
{
int t_s= time((time_t*)NULL);
printf("\nstart time:%d",t_s);
char* file_path_from; /* path to source file. */
char* file_path_to; /* path to target file. */
FILE* f_from; /* stream of source file. */
FILE* f_to; /* stream of target file. */
char buf[MAX_LINE_LEN+1]; /* input buffer. */
/* read command line arguments */
if (argc != 3 || !argv[1] || !argv[2]) {
fprintf(stderr, "Usage: %s <source file path> <target file path>\n",
argv[0]);
exit(1);
}
file_path_from = argv[1];
file_path_to = argv[2];
/* open the source and the target files. */
f_from = fopen(file_path_from, "r");
if (!f_from) {
fprintf(stderr, "Cannot open source file: ");
perror("");
exit(1);
}
f_to = fopen(file_path_to, "w+");
if (!f_from) {
fprintf(stderr, "Cannot open target file: ");
perror("");
exit(1);
}
/* close source and target file streams. */
if (fclose(f_from) == EOF) {
fprintf(stderr, "Error when closing source file: ");
perror("");
}
if (fclose(f_to) == EOF) {
fprintf(stderr, "Error when closing target file: ");
perror("");
}
/*compute jiecheng*/
int i=1 ;
double tempresult=1;
for(i=1;i<=50;i++)
{
tempresult=tempresult * i ;
printf("%d\n",i);
printf("%f\n",tempresult);
}
printf("\n 50!= %f \n",tempresult);
f_to = fopen(file_path_to,"a+");
char Line[100];
sprintf(Line,"%f",tempresult);
fprintf(f_to,"%s",Line);
fclose(f_to);
int t_e= time((time_t*)NULL);
printf("\nendtime is :%d",t_e);
int usedtime;
usedtime=t_e - t_s;
printf("\nused time is :%d",usedtime);
}
#include <time.h>
#define MAX_LINE_LEN 1000 /* maximal line length supported. */
void main(int argc, char* argv[])
{
int t_s= time((time_t*)NULL);
printf("\nstart time:%d",t_s);
char* file_path_from; /* path to source file. */
char* file_path_to; /* path to target file. */
FILE* f_from; /* stream of source file. */
FILE* f_to; /* stream of target file. */
char buf[MAX_LINE_LEN+1]; /* input buffer. */
/* read command line arguments */
if (argc != 3 || !argv[1] || !argv[2]) {
fprintf(stderr, "Usage: %s <source file path> <target file path>\n",
argv[0]);
exit(1);
}
file_path_from = argv[1];
file_path_to = argv[2];
/* open the source and the target files. */
f_from = fopen(file_path_from, "r");
if (!f_from) {
fprintf(stderr, "Cannot open source file: ");
perror("");
exit(1);
}
f_to = fopen(file_path_to, "w+");
if (!f_from) {
fprintf(stderr, "Cannot open target file: ");
perror("");
exit(1);
}
/* close source and target file streams. */
if (fclose(f_from) == EOF) {
fprintf(stderr, "Error when closing source file: ");
perror("");
}
if (fclose(f_to) == EOF) {
fprintf(stderr, "Error when closing target file: ");
perror("");
}
/*compute jiecheng*/
int i=1 ;
double tempresult=1;
for(i=1;i<=50;i++)
{
tempresult=tempresult * i ;
printf("%d\n",i);
printf("%f\n",tempresult);
}
printf("\n 50!= %f \n",tempresult);
f_to = fopen(file_path_to,"a+");
char Line[100];
sprintf(Line,"%f",tempresult);
fprintf(f_to,"%s",Line);
fclose(f_to);
int t_e= time((time_t*)NULL);
printf("\nendtime is :%d",t_e);
int usedtime;
usedtime=t_e - t_s;
printf("\nused time is :%d",usedtime);
}