as the problem i'd met b4:
http://www.daniweb.com/forums/thread115104.html

there's another problem looks like same with that problem,
is about the logic of the int outq.
this make the result1.txt always get unknown words after few loops.

i'd like to know how to correct it.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fstream>
#include <iostream>
#include <string.h>
#include <cctype>

using namespace std;
using std::string;

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

    int noofline = 10;
    int q = 0;
    int outq = 0;

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

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

    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<noofline;){

        fscanf(finput,"%d", &timeslot1[i]);
        fgets(packe[q].strinput, 38, finput);

        fscanf(fcommand,"%d", &timeslot2[i]);
        fgets(comm[i].strcommand, 25, fcommand);

        cout<<timeslot1[i]<<packe[q].strinput<<endl<<comm[i].strcommand<<endl;

        if(packe[q].strinput[5] == '8') {q++;}

        if(comm[i].strcommand[8] == 't'){
            fprintf(creafile, "%d %d \n", timeslot1[i], q);
            cout<<"the data in file : "<<timeslot1[i]<<"  "<<q<<"  ";
        }
        else if(comm[i].strcommand[1] == 'i'){
            fprintf(creafile, "%d \n", timeslot1[i]);
            cout<<"the data in file : "<<timeslot1[i]<<"  ";
        }
        else{
            fprintf(creafile, "%d %s \n", timeslot1[i], packe[outq].strinput);
            cout<<"the data in file : "<<timeslot1[i]<<"    "<<packe[outq].strinput;

            outq=outq+1;
            q=q-1;
        }
        cout<<comm[i].strcommand[1]<<"  "<<comm[i].strcommand[8]<<endl;

        cout<<"queue = "<<q<<"  outq = "<<outq;
        cin.get();
        i++;
    }

    cout<<"Last queue no. is "<<q<<endl;

    fclose(finput);
    fclose(fcommand);
    fclose(creafile);

    cout<<"Press enter to continue...";
    cin.get();
    return(0);
}

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
7 C0A80001 91BD C0A80002 0050 21E89A
8 C0A80001 D10A C0A80002 0050 32DCE1
9 C0A80001 AB4F C0A80002 0050 34EF
10

command1.txt

1 output
2 output the queue length
3 idle
4 output
5 output
6 output the queue length
7 output
8 output
9 output
10 output

then result1.txt should be as below:

1 C0A80001 8F22 C0A80002 0050 32D5B9C
2 1
3
4 C0A80001 8B05 C0A80002 0050 12D67B
5 C0A80001 CC08 C0A80002 0050 32D5B9C
6 1
7 C0A80001 C4A3 C0A80002 0050 34F1
8 C0A80001 91BD C0A80002 0050 21E89A
9 C0A80001 D10A C0A80002 0050 32DCE1
10 C0A80001 AB4F C0A80002 0050 34EF

thank you.

this problem i'd solved it already, thanks a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.