954,506 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

problem of data output into *.txt file

as the project given input1.txt and command1.txt to create result1.txt

input1.txt:
1 C0A80001 8F22 C0A80002 0050 32D5B9C
2 C0A80001 8B05 C0A80002 0050 12D67B
3 C0A80001 CC08 C0A80002 0050 32D5B9C
4
5
6 C0A80001 C4A3 C0A80002 0050 34F1

command1.txt1 output
2 output the queue length
3 idle
4 output
5 output
6 output the queue length

then result1.txt should and must be:1 C0A80001 8F22 C0A80002 0050 32D5B9C
2 1
3
4 C0A80001 8B05 C0A80002 0050 12D67B
5 C0A80001 CC08 C0A80002 0050 32D5B9C
6 1

but at last i'd get the actual result1.txt as below:1 D
2 y燙
3 D
4

5

6 L?

i would like to know that which problem of the below programme meet and how to correct:#include
#include
#include
#include
#include
#include
#include

using namespace std;
using std::string;

int main(void)
{
FILE * finput;
FILE * fcommand;
FILE * creafile;

int noofline = 10;
int q = 0;

typedef struct pac{
char strinput[38];
};
typedef struct com{
char strcommand[25];
};

struct pac packe[noofline];
struct com comm[noofline];

int timeslot1[noofline];
int timeslot2[noofline];

finput = fopen("input1.txt","r");
fcommand = fopen("command1.txt","r");
creafile = fopen("result1.txt","w");

for(int i=0; i

ps: this programme still in modified, the main problem i'd met is
unable to write the correct char packe[q].strinput into result1.txt (that should be C0A80001*****)
it always give me unknown words.
thank you.

nelsonsu
Newbie Poster
8 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

Since I don't see that you've posted to the C board and you are using pure C syntax within the code I'd encourage you to post there.

I note a problem with the syntax you're using to declare arrays. When declaring arrays the size needs to equate to a const int, not int, which is what noofline is.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 
if(packe[q].strinput[0] == ' ') 
{
    q++;
    // Because you have incremented q by one,
    // the fprintf() call below is guaranteed to produce
    // unwanted output ...
}

// You must change your code so that you know whether to use 
// packe[q].strinput or packe[q - 1].strinput ...
fprintf(creafile, "%d %s \n", timeslot1[i],  packe[q].strinput);
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 

thank you, its work.

nelsonsu
Newbie Poster
8 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You