Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,501 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,376 people online right now. Registration is fast and FREE... Join Now!




output format

 
Reply to this topicStart new topic

output format

gamodg
22 Mar, 2007 - 12:42 PM
Post #1

New D.I.C Head
*

Joined: 14 Mar, 2007
Posts: 10


My Contributions
presenting here a program fragement of my project
two files mainn.txt mp.txt format i have given at the end of this code
the problem is that while printing mp.txt the output is not in format as i expected

CODE

[color=#33CC00]DF: 1
SA: 2-2         DA: R1          D: 3
SA: R1          DA: R1          D: 2
SA: R1          DA: R1          D: 1
SA: R1          DA:               D: 0
ID: 3
[/color]


but is of the form


[color=#FF0000]
DF: 1
SA: 2-2         DA: R1          D: 3
SA: R1          DA: R1          D: 2
SA: R1          DA: R1     D: 1
SA: R1     DA:      D: 0
ID: 3[/color]  

i tried using tab and setw but output is not coming the way i expect it to be


#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<stdio.h>
#include<iomanip.h>
#include<stdlib.h>
#include<dos.h>
int countk=0,k=4,probab=1;
char str[20],*p,*q,buf[100],*w,d1[10];
class router
{
    public:
       void extract(char *p,char str[])
        {
            int i=0;
            while(p && i<4)
            {
                str[i]=*p;
                p++;i++;
            }
            str[i]=NULL;
        }

           
      void mp_entries(fstream &mp)
        {
          cout<<setw(20)<<"\n In mp_entries function \n\n";
          char l[20];
          int i;
          p=q=w=NULL;
          fstream t;
          t.open("c:\\p\\temp",ios::in|ios::out|ios::trunc);
          mp.seekg(0);
          while(!mp.eof())
          {
            mp.getline(buf,100);
            p=strstr(buf,"SA:");
            if(p)
            {
            ++countk;
            p+=4;
            extract(p,str);
            q=strstr(buf,"DA:");
            q=q+4;
            w=strstr(buf,"D:");
            w+=2;
            i=atoi(w);
            ++i;
            if(*q<='0')
            {

               t<<"SA: "<<str<<"\t"<<" DA: R1"<<"\t"<<" D: "<<i<<"\n";
            }
            else
            {
              extract(q,l);
              t<<"SA: "<<str<<"\t"<<" DA: "<<l<<"\t"<<" D: "<<i<<"\n";
            }
              }
             else
             {
              p=strstr(buf,"ID");
               if(p && probab==1 && countk<k)
            {
              t<<"SA: R1"<<"\t"<<" DA: "<<"\t"<<" D: 0\n";
            }

              if(p)
              {
            t<<"ID: "<<countk<<"\n";

              }
              else
              {
            t<<buf<<"\n";
              }
           }
           }

          mp.close();
          t.close();
          remove("c:\\p\\mp.txt");
          rename("c:\\p\\temp","c:\\p\\mp.txt");
          fstream file;
          file.open("c:\\p\\mp.txt",ios::in|ios::nocreate);
          while(!file.eof())
            {
                file.getline(buf,100);
                cout<<buf<<endl;
            }
          file.close();
         }
      
void main()
{
fstream f;
f.open("c:\\p\\mp.txt",ios::in|ios::out|ios::nocreate);
clrscr();
router r;
r.pkt_type(f);
f.close();
getch();
  }


Mainn.txt

DF:0
Uflag:1
Source :2-2
Destination :2-22
Data :sdssdds

Mp.txt

DF: 1
SA: 2-2 DA: R1 D: 1
SA: R1 DA: D: 0
ID: 1

This post has been edited by gamodg: 22 Mar, 2007 - 12:58 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 06:39PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month