dchunt 0 Newbie Poster

I want to run the programs r1-r4 and n1-n4 simultaneously instead of waiting for each one to finish executing,I've been stuck on this for a long time, i went through multi threading for c++ in dev-cpp and the Win API code is quite complicated. Can somebody provide the code to execute them simultaneously or any other easy way i can implement it.

Thank you.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cstdlib>
#include <conio.h>

using namespace std;
             
int main()
{
    
ifstream od,od2,od3,od4,od5,od6,od7,od8;
ifstream odd,odd2,odd3,odd4,odd5,odd6,odd7,odd8;
string line;
int num[8],nu=0;


system("r1.exe");system("CLS");
system("r2.exe");system("CLS");
system("r3.exe");system("CLS");
system("r4.exe");system("CLS");

system("n1.exe");system("CLS");
system("n2.exe");system("CLS");
system("n3.exe");system("CLS");
system("n4.exe");system("CLS");



od.open("r1.txt");
getline(od,line);
num[nu]=atoi(line.c_str());
nu++;
od.close();

od2.open("r2.txt");
getline(od2,line);
num[nu]=atoi(line.c_str());
nu++;
od2.close();

od3.open("r3.txt");
getline(od3,line);
num[nu]=atoi(line.c_str());
nu++;
od3.close();

od4.open("r4.txt");
getline(od4,line);
num[nu]=atoi(line.c_str());
nu++;
od4.close();

od5.open("n1.txt");
getline(od5,line);
num[nu]=atoi(line.c_str());
nu++;
od5.close();

od6.open("n2.txt");
getline(od6,line);
num[nu]=atoi(line.c_str());
nu++;
od6.close();

od7.open("n3.txt");
getline(od7,line);
num[nu]=atoi(line.c_str());
nu++;
od7.close();

od8.open("n4.txt");
getline(od8,line);
num[nu]=atoi(line.c_str());
nu++;
od8.close();




int best=0;
best=num[0];

for(int i=0;i<nu;i++)
{
if(num[i]>best){best=num[i];}
}


cout << best ;


cin.get();
return 0;
 
}
dchunt 0 Newbie Poster

I put all the contents of an array a[16] into a file. But when i read them how can i separate those numbers from each other instead of adding a space.

what about putting the contents into a new line like
0 14
1 24

How do i do that and read it,is there any easier solution ? i am just a beginner,so keep it simple.
Thanks.

dchunt 0 Newbie Poster

I have a file over 100 Kb long. I want to perform operations on successive batches of 256 characters.

int fs=0;
char ss[32556];
ifstream nm,nm1;
nm1.open("as86.txt");
if(nm1.is_open())
{
    nm1.seekg(0, ios::end ); 
    fs = nm1.tellg();
    
}
nm1.close();

nm.open("as86.txt");
nm.read(ss,fs+1);
nm.close();

cout << endl << fs << endl;

ofstream mn;
mn.open("as86.txt");
for(int jm=256;jm<fs;jm++){mn << ss[jm];}
mn.close();

Now i've been reading it using arrays and writing them from the 256th charcter back into the file.I guess arrays can't hold that many values and my text file gets corrupted.

Is there any command in the stream classes to remove the first 256 characters from a file or better array implementation that i can use ?

dchunt 0 Newbie Poster

Say i have a 256 byte file. How many additions or multiplications can a modern computer perform on them using c++ ?

I've been working on this c++ compression project that does a lot of calculations. I use Dev-cpp,and am a amateur programmer,i've not used pointers,vectors or anything fancy yet,anyway my comp takes about 10 secs to just reduce it by a few bytes. How much faster can i expect it to run if i use vectors and pointers ?

And finally When a computer has a spec of 2GHZ,and a cycle period of 2,does it mean it performs a billion instructions ? and what constitutes a instruction ? a file transfer,addition, how many of these operations can fit in 1 instruction ? Does assinging or incrementing a variable count a 1 instruction ?

Thanks a lot for your time and response.

dchunt 0 Newbie Poster

It takes a long time for my comp to execute this simple loop.


Now the final do while gives me the problem,even if i use if statement,it takes about 10 secs before displaying the result,which is quite ridiculous.

int counters[255] = {0};

   ifstream in("ut2.txt", ios::binary);
   unsigned char c;
   while( in.read((char *)&c, 1) )
   {   
   counters[c]++;
   }

   int h1=0,hm=0;

   
   int da=0;
   for(hm=0;hm<256;hm++)
   {
   da=counters[hm]+da;
   }
   da=da/256;




   do
   {
   h1=0;   
  
   for(hm=0;hm<256;hm++)
   {
   if(counters[hm]>=da){h1++;}
   }
  
   da--;
   if(h1==192){da++;break;}
   }
   while(h1<=192);

Can i use h1 as the condition for while and change it to 0 in the main loop ?

dchunt 0 Newbie Poster

I've written a few simple C++ programs in Dev-cpp... Now i want to run the second program inside the first in case it satisfies a condition. It then geneerates a text file from which new values are got. Is it possible to do that ? I'm just a beginner and don't want to do any complicated things right now. And i can't just copy paste the code onto the first one because a lot of values and variables will conflict with each other.

Really need help on this
Thanks for your help..

dchunt 0 Newbie Poster

My text file contents are in the form "00101010111101101011".

I want to read it from the file and send each digit to an array,unfortunately i'm only able to use char while reading a file.How do i send each digit onto an array?a

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <string>
#include <cstdlib>



using namespace std;
             
int main()
{
    
char st[32];
int y[32]={0},n=0;
int fstd=0;

ifstream std;
  
 
std.open("std.txt");
if(std.is_open())
{
    std.seekg(0, ios::end ); 
    fstd = std.tellg();
}

 std.read(st,fstd);
 std >> st[n];
 n++;
 std.close();
 cout <<endl;
 
 
 for(int i=0;i<=fstd;i++){  
 y= (unsigned char) st[i];        
 cout << st[i] << " ";
 }

  
  cin.get();
  return 0;
 
}
dchunt 0 Newbie Poster

Jonsca,I love you!!!!

This problem has been bugging me for weeks.Thanks a million.

I didn't know i had to use read instead of get.

Anyway when i take off the binary mode it starts displaying a 0 in between every other numeric value,so i've let it as it is.And also the (CC,17) thing bugged me,but when i change it to (CC,16) it only reads 15 characters.

Thanks a lot sir.

dchunt 0 Newbie Poster

I want to read characters(256 of them) from a file and put thier numeric value in an array.Then i want to send 16 characters in batches from the array onto a loop in successive steps to perform operations on them.

My problem:

First i can read the first batch of 16 characters easily. But after the second or third it starts showing 0,32 or 255 as the characters,but there are no spaces and it does not read the character but just fills it with blanks.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>


using namespace std;


                  
int main()
{
    
    
   int size=0;
   int ff=0,ww=0,g=0,h=0,l=0;
   
   char cc[256];
   int a[256];


   ifstream infile;
   ofstream myfile;
   infile.open("as86.txt",ios::binary);

  infile.get(cc,257);  
  infile.close();  
  }
  
  cout <<< endl;

do

{

    h=g+16;

    
    for(int i=g;i<h;i++){
  a[i] =  (unsigned char)cc[i];
  cout << a[i] << "  ";
  }

g=h;
l++;

}

while(l<=15);

Now unfortuantely it only prints about thew first 32-35 characters properly,after that it goes haywire.

What's wrong ? Any better ways to read character from file and send thier numeric value into an array.

Thanks.

dchunt 0 Newbie Poster

Say i have this 10,000,000 (10 million) byte file.

I want to perform multiplication,addition and few other operation on all those bytes(total of 5). And after it is done say if i want to repeat the addition and other operations on the same file like a loop,then

How many such instructions can i execute in a programming language like c++?

Also when they say instructions,does one instruction count as a operation on every bit or byte or does it mean an actuall addition operation ?? and how does cycles and hertz fit inside all of this ??

I really want to know how much a processor can compute in a second,so

Thankyou and have a new year..

dchunt 0 Newbie Poster

Is there any language or way to write a program that is about 10000 lines in such a way that it can't be re-engineered by decompiling it ? What options are available to pursue ?

Thank you for your time..

dchunt 0 Newbie Poster

Yes i tried that too but quite a few of the symbols where different.

Binary format :
┼╜:♀╤ô1∞↑∩▬Zσô*▓ws┐Q→£u!Ñ╢T¢÷ûÄFès┘Jr»fÑ≡XεR╟?∙

Actual output :
Ž:Ñ“1ìïZå“*²ws¿Qœu!¥¶T›ö–ŽFŠsÙJr¯f¥åðXîRÇ?ù

Any other suggestions ?

dchunt 0 Newbie Poster

I've wanted to write a program to read the extended characters from a file.

#include <iostream>
#include <fstream>

using namespace std;

int main()
{                     
  
 char a,ch[50]; 
 long l, m, k;
 
 ifstream infile;
 infile.open("as6.txt");
 l = infile.tellg(); 
 infile.seekg(0, ios::end);
 m = infile.tellg();
 k = (m - l);
 infile.seekg(0, ios::beg);
 
 while(infile!=0)
 {
 infile.get(ch,50);
 cout << ch;
 }
 infile.close();
 
 cout << endl << k;
 
 cin.get();
 return 0;

}

The output is displayed as :

┼╜:♀╤ô1∞↑∩▬Zσô*▓ws┐Q
49

Wheras the output from the text file is :

Ž:Ñ“1ìïZå“*²ws¿Qœu!¥¶T›ö–ŽFŠsÙJr¯f¥åðXîRÇ?ù

I tried opening the file in binary format :
┼╜:♀╤ô1∞↑∩▬Zσô*▓ws┐Q→£u!Ñ╢T¢÷ûÄFès┘Jr»fÑ≡XεR╟?∙

Now some charcters are displayed,other not!

Completely different symblos !! First i thought the console window couldn't print those charcters so i worte another program

#include <iostream>
int main()
{
     char a = 156;
     unsigned int b = int (a);
     std::cout << a;
     std::cout << b;
     std::cin.get();
     return 0;
 }

It prints the character perfectly in this instance.

How do i correct it ?

dchunt 0 Newbie Poster

Now i learnt basic windows programming long time ago and now use dev-cpp,i can run the simple Hello World program in that,but don't know how or where to implement cout and if statements type programming ?

#include <windows.h>


LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);


char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               
    MSG messages;            
    WNDCLASSEX wincl;        

    
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;     
    wincl.style = CS_DBLCLKS;                 
    wincl.cbSize = sizeof (WNDCLASSEX);

   
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                
    wincl.cbClsExtra = 0;                     
    wincl.cbWndExtra = 0;                     
   
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

 
    if (!RegisterClassEx (&wincl))
        return 0;

   
    hwnd = CreateWindowEx (
           0,                 
           szClassName,       
           "Windows App",      
           WS_OVERLAPPEDWINDOW, 
           CW_USEDEFAULT,       
           CW_USEDEFAULT,     
           544,               
           375,               
           HWND_DESKTOP,       
           NULL,              
           hThisInstance,       
           NULL         
           );

    
    ShowWindow (hwnd, nFunsterStil);

  
    while (GetMessage (&messages, NULL, 0, 0))
    {
    
        TranslateMessage(&messages);
      
        DispatchMessage(&messages);
    }

  
    return messages.wParam;
}




LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)                 
        {
                                     case WM_DESTROY:
            PostQuitMessage (0);       
            break;
        default:                     
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

So what i tried was adding another source file and compiling it but nothing happens.

#include <iostream>
int main()
{
     char a = 156;
     unsigned int b = int (a);
     std::cout << a;
     std::cout << b;
     std::cin.get();
     return 0;
 }

Where do i implement it ?

dchunt 0 Newbie Poster

cout << fixed << setprecision(2) << b ;

This will keep it to 2 decimal places.

Now i have a problem !! when you do that it will round off the values to about 3.15,i had a similar problem earlier to which i have not yet found a solution.

How do you make sure it does not round off the value,in my case the value was 0.003974 , how do i get only 0.003 ?

dchunt 0 Newbie Poster

Open the file in binary mode, not text, then read each byte into an unsigned char, which has a value 0-255. If you want to count the number of occurrences all you need is an array of 255 and use the char as the index into the array

int counters[255] = {0}

ifstream in("myfile.bin", ios::binary);
unsigned char c;
while( in.read((char *)&c, 1) )
{
   counters[c]++;
}

Thanks a lot,but i'm new to this and don't understand this part

while( in.read((char *)&c, 1) )

Why the use of a pointer and why reference &c ?

dchunt 0 Newbie Poster

I want to write a program to read a audio file and classify the various symbols into the number of times they occur , I was hoping i could use a switch statement and classify the 256 symblos but now i've learnt the standard ascii set is only from 0-127,so the rest of the symbols would vary from system to system?.

So how do i go on reading these symbols such that it would work on any system and also how can i access thier decimal values ??

I'm just hoping somebody points me in the right direction,Thankyou.

dchunt 0 Newbie Poster

Is it possible to create a series like this

char j;
int ,k;
for(int i=0;i<10;i++){
k=ji;
}

I get an error but want to create something like
j0
j1
j2
and so on...

How do i do that ?

dchunt 0 Newbie Poster

Now i have an array, P[8]={0,1,1,2,0,3,1,0}

And i want to add 4 separate values to each element in the array,so if i was to lookup P[2] i can access its 4 values.

I tried doing it by giving those standard values an array of itself and making each value get it through a loop but a fundamental problem occurs when assinging P[6] to those 4 values cause it kind of makes the array size 6,anyway i think i've got some concept confused.Is it possible ? How do i circumvent it ?