We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,285 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

C program to copy and rename output report files in a continuous simulation

I am very new to programming language and need help urgently. I am running a program which gives me one output file for every 5 min simulation. i have to copy and rename the output file in each step so that they can be used in another program . Any suggestions on how to do it with a single code for 10 runs of continuous simulation ? so far i could manage only this which is like this :

#inlcude<stdio.h>
#include<math.h>
#include<string.h>
FILE *foriginal, *fcopied;


int main()
{

char c2[80];
int i;
foriginal=fopen("100_fe.rpt","r");

while (fgets(line, 80, foriginal) != NULL)
{
      fprintf(foutp,"%s",line)if(t2[i]==' ') t2[i]='0';
  }
sprintf(c2, "%4i" ,save);
for (i=0;i<4;i++)
strcat("100_fe.rpt",c2);
fcopied=fopen("100_fe.rpt", "w")
return 0;
}

I am not sure if I am going the right way as I am really a beginner in programming world. Please help me out in this matter. thanks.

3
Contributors
3
Replies
7 Hours
Discussion Span
6 Months Ago
Last Updated
4
Views
celina1234
Newbie Poster
11 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

correction please : #include is spelled wrong and t2 shall be c2. Thanks.

celina1234
Newbie Poster
11 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

i have to copy and rename the output file in each step so that they can be used in another program .

"Copy" AND "Rename"? So you start with a file named a.txt and you are supposed to end up with what? one file? Two files? A file named a.txt and a file named b.txt? A file named b.txt and a file named c.txt?

From your description, you may want to make a couple of calls using the system command...

system("cp a.txt b.txt"); // Linux copy
system("mv a.txt b.txt"); // Linux rename

This may or may not be what you are looking for, so you may need to elaborate on the overall goal that you have. The above solution uses system calls to the operating system and avoids the need for any printf, gets, and FILE* code.

VernonDozier
Posting Expert
5,675 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 738
Skill Endorsements: 18

Celina, can you write out in plain English, a description of what you want, step by step:

1) get input - this is an example:
"example of input here"

2) process or calculate some here

3) give output like this, to a file with a numbered name, every 5 minutes
"example of output here" ------ fileN.rpt where N is the next number

4) do this 10 times.

something like that, but with clear examples of the input and output, etc.

General descriptions are OK for most things, but programming requires a great deal of specific details.

Adak
Posting Virtuoso
1,640 posts since Jun 2008
Reputation Points: 456
Solved Threads: 196
Skill Endorsements: 7

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.3187 seconds using 2.7MB