rahul8590 71 Posting Whiz

As Waltp said , u gotto create a new file with .h extension and then transfer the complete class code into it .
In the main program call

#include "counter.h"

and then create the class object to use all the methods inside it.

rahul8590 71 Posting Whiz

Well it runs in MinGW and i am very happy with that , Certainly for my seminal project ideas i would keep that in mind.

rahul8590 71 Posting Whiz

Kudos to you ,

I could diagonise and fix it correctly , but have some memory issues like the rest of the integer array is holding some arbitrary numbers and i would to truncate the array till extracted digits.


Srry ,
I solved that issue too .
Now , if i want to put this in a header file and call it in some other program , how do i go about doing that.

rahul8590 71 Posting Whiz

Well ,it may sound a bit preposterous , but i have a pretty weird problem (which i have solved many times , dunno why it isnt working for me this time ) .

I have a data file from which i randomly pick up row nos . The data file has list of integers , actually they are co ordinates of a mathematical equations .

I only extract out the numbers from them and filter out the -ve symbols and decimals .
I am able to print those extracted numbers on screen , but not able to transfer the number as it is into another integer array.

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




using namespace std;

int main () {
  string  line;
  int linesize , guess;

  srand ( time(NULL) );                               // For random line to be choosen
  guess = rand() % 10 + 1;                             // this random number must be a multiple of 39
  guess = guess * 39 ;
  cout<<" the randomly choosen line number is "<<guess/39<<endl;



  ifstream myfile ("data.txt");
  if (myfile.is_open())
  {
                   myfile.seekg (guess, ios::beg);   // positioing the start of each line to fetch all the coordinates
      getline (myfile,line);
      cout << line << endl;
}

else cout << "Unable to open file";

  linesize = line.size();

  int aint[linesize];               // The arrays satisfying the condition  
                                            //in integer form


  cout<<" \n \n the char array of the same is "<<endl;

char *a=new char[line.size()+1];  // Conversion of string to char  
a[line.size()]=0;                             //array
memcpy(a,line.c_str(),line.size());



  for ( int i = …
rahul8590 71 Posting Whiz

Well i have downloaded recuva and i hope that it works for me.
I have not formatted the partition and have abstained it from any data transactions .

Can i perform quotidian work in other drives ?

rahul8590 71 Posting Whiz

I have a 160 gb partition in my system and accidentally i have deleted all my movie files using shift + delete .
Is there any way i can recover the data back somehow. its mainly all video files .

rahul8590 71 Posting Whiz

Well i think you arent getting the point. I am aware about the output and how it is coming but the gist is
"I want the ascii of that character to be printed i.e 100 for d . So ,if the file contains a list of characters , i need the program to display the ascii of these letters not the binary equivalents , besides the operation should be reversible i.e to get back the characters from their ascii notations. "

rahul8590 71 Posting Whiz

Well i think you arent getting the point. I am aware about the about and how it is coming but the gist is
"I want the ascii of that character to be printed i.e 100 for d . So ,if the file contains a list of characters , i need the program to display the ascii of these letters not the binary equivalents , besides the operation should be reversible i.e to get back the characters from their ascii notations. "

rahul8590 71 Posting Whiz

I got this silly problem and honestly dunno why it isnt working .
The scenario is i got a text file with information and i got to print the ASCII equivalent of the text into the screen .
While attempting to do so , i am getting the binary equivalent (well apparently it doesnt seem so ).

#include <iostream>
#include <fstream>
using namespace std;

int main () {
  int c;
  char str[10];
  ifstream is;

  cout << "Enter the name of an existing text file: ";
  cin.get (str,10);

  is.open (str);        // open file

  while (is.good())     // loop while extraction from file is possible
  {
    c = is.get();       // get character from file
    cout << c ;
  }

  is.close();           // close file

  return 0;
}

I have a test.txt file where in i have store only "d" character (without quotes)

the output got is :
1001010-1

but i want it to print it as 100

although , if i run this program i.e to find the ascii eq i get the right output .

#include<iostream.h>
using namespace std;
int main ()
{
  char a = 'd';
  int x = a;
  cout<<x;
  return 0;
}
rahul8590 71 Posting Whiz

well then u gotto to be a little specific here ,
AS far as i guess , ur saying ur not able to run graphic program
the possible reasons could be

1. there is no graphic lib
2. There exist graphic lib but , its not linked to

Notepad++ is a code editor thats all , its got nothing to do with ur graphics not running,

rahul8590 71 Posting Whiz

Well one thing i would suggest would be in every case , ur opening the file and then closing it , that generates redundant code.

else if (a == 2) {
string fileData;
ifstream itemFile ("item.txt");
itemFile.close();
else if (a == 3) {
ifstream itemFile ("item.txt");
itemFile.close();

u could perform that action once in for all , after all the job is done and the user wants to quit fro the program , u can close the file.

rahul8590 71 Posting Whiz
rahul8590 71 Posting Whiz

Well for graphic programming there are 2 major tools (well not exactly tool)

1. OpenGL
2.DirectX

Since u want windows oriented ,it would be prudent to go with DirectX .

This will get u started.

http://www.two-kings.de/tutorials/dxgraphics/

rahul8590 71 Posting Whiz

>4 and 7 is also prime number but it is not in the output..

1. 4 Cannot be a prime number .

2. At line 34 , there is no need or resetting it to true .

3. At line 19 interate the "i" from 1 to n

I guess this should solve ur problem .

An improvised version of ur code

for (i=1;i<=n;i++)
   {
        prime=true;

        for (j=2;j<i;j++)
        {
            if (!(i%j))
            prime=false;
        }   
        if(prime)
        cout<<i<<endl;

    }
rahul8590 71 Posting Whiz
rahul8590 71 Posting Whiz

Well , i am not sure of a API whether i exist or not and even if there exist an API , the purpose will not completely be fulfilled .

For example :
Even if u write a program which doesnt allow to access internet after a time , the user can use other programs or tools to bypass it .

Although there is a way that can implement wat u asked and that is installing a proxy server in ur system .
i have myself done that in my college for regulating the internet access in each departments .
SQUID proxy server allows u to perform many functions like that.
Not only u can create a ACL (access control list ) but also assign user groups and set their time of access and other attributes.

rahul8590 71 Posting Whiz

i think , this would help u .
http://easybmp.sourceforge.net/

its was of great help for me.

rahul8590 71 Posting Whiz

I am able to write a java program to access a particular url , and get the data , but the data is in raw format and the complete source is printed in the terminal .

import java.net.*;
import java.io.*;

public class URLConnectionReader {
    public static void main(String[] args) throws Exception {
        URL go = new URL("http://www.google.com/");
        URLConnection uc = go.openConnection();

        BufferedReader in = new BufferedReader(
                                new InputStreamReader(
                                uc.getInputStream()));
        String inputLine;

        while ((inputLine = in.readLine()) != null) 
            System.out.println(inputLine);
        in.close();
    }
}

I want that raw data to be displayed as a web page. Is there any way to do that.

rahul8590 71 Posting Whiz

Well
1. , if i am not wrong ur working on turbo C compiler .
2. there is a help documentation in that itself on how to use the clock function.
3.it would be better , to print (end-start)/clk_tck
4. The output u will fetch will be 0 seconds for the basic operational code.
i.e if the clock is been started when the actual quicksort happens not when ur entering the numbers.

5. Please stop using turbo C , compiler .... there are much better ones than this outdated one.

rahul8590 71 Posting Whiz

1. People need not to have a single character as a password , ur code works only for a single character.

2. Goto is a very very bad & unstructured style of programming , double whammies like that are rare.

3.For , god sake stop using the old freaking turbo C++ compiler , there are much better compilers like gcc, boroland etc.

Salem commented: 3 EXCELLENT points! +18
jonsca commented: Yes-Please recycle anything else except for Borland code +1
rahul8590 71 Posting Whiz

Well i am not an expert when it comes to java thread , but i guess this

1. u have mentioned a catch block , but i dont see the code for try block.

2. when the thread.sleep() is executed , the other concurrent thread must start running , provided u have mentioned the code in the run() method for the other class object.

rahul8590 71 Posting Whiz

Hello everyone , i am trying to create a multi threaded web server, i did the basic part (socket programming ) successfully .

Ref: http://www.daniweb.com/code/snippet217312.html

now , the next step , i am trying to establish it by making it multi thread or repetetive polling for client request (yet to decide)

The problem i am facing , is i want to create a shared memory pool where the client can access the list of files in the server.

Example :
There exist a folder named share and there exist some files , in it.
Now , if client request to access the files , it server has to find the file and then send it to the client .
Is it possible ? if yes , could u enlighten me on how to implement it.

rahul8590 71 Posting Whiz

> any idea for how to proceed for testing ?
Only for you to show that whatever your encryption process is reversible.

Well thats exactly wat i was looking for . . i got my cipher , so basically in the buffer where i have stored the complete data has to be encrypted and then reversed.

> I mean is there any other complications of hexadecimal of so .
Only that in hex, a single byte can always be nicely formatted as two characters.

Well as of now i am getting in numbers right ..?
Ur saying if i convert into hex , things will be more organized .

rahul8590 71 Posting Whiz

its working without the hex in the cout statement u gave .
Is that the true data of the movie/audio file. ? I mean is there any other complications of hexadecimal of so .

the changed code instead of simply printing the buffer array i :

cout<< int(buffer[i]) ;

and this worked . I was getting numbers .

any idea for how to proceed for testing ?

rahul8590 71 Posting Whiz

well tried opening it , its was kinda successful . but when i try printing the data of the avi file i am getting all junk characters.

#include <iostream.h>
#include <fstream.h>

const char * filename = "twilight.avi";

int main ()
{
  long l,m;
  ifstream file (filename, ios::in|ios::binary);
  l = file.tellg();
  file.seekg (0, ios::end);
  m = file.tellg();
  file.close();
  cout << "size of " << filename;
  cout << " is " << (m-l) << " bytes.\n";
  return 0;
}

i could print the size of the file , but i want to save the data in a buffer array i am getting junk values

#include <iostream.h>
#include <fstream.h>

const char * filename = "twilight.avi";

int main () 
{
  char * buffer;
  long size;
  ifstream file (filename, ios::in|ios::binary|ios::ate);
  size = file.tellg();
  file.seekg (0, ios::beg);
  buffer = new char [size];
  file.read (buffer, size);
  file.close();

  cout << "the complete file is in a buffer";

  cout<<endl;
    int i;
  
for ( i=0;i<size;i++)
  cout<<buffer[i];     // here i am trying to print the data inside buffer where i get all junk values.

  return 0;
}
rahul8590 71 Posting Whiz

i am aware of time command ,

But the point is , i have to process the audio / video file which i am inputting as an argument.

for example ,
if i am passing a movie name twlight.avi
it must be something like this

$ ./program twilight.avi

then i must be able to fetch the movie in form of bytes or so .
When i get the movie files in stream of bytes , then i can apply my encryption procedure on it and then again get a stream of bytes that are similar to that of movie but are encrypted.
Thats the complete procedure .

But i have never processed a movie or audio file before , so i want to know how do i proceed with that.

rahul8590 71 Posting Whiz

Like for compression, as far as you're concerned, it's just a meaningless array of bytes to encrypt. So long as you get back what you put in, why do you even care what the file is for?

well , thats exactly what i think. But my implacable professor isnt convinced with it.
And wats infinetly worst is i have been told to demonstrate by inputting the mov.audio file name as an argument and asked to show the time for processing that.
I could do that for a text file , but have no idea for the mov/audio files.
Besides , i am not much concerned with compression as of now , just want to make this thing work.

rahul8590 71 Posting Whiz

I kinda understood vaguely . is there any sample program u can quote ?

rahul8590 71 Posting Whiz

Well for past few months now i have been doing my research on encryption cipher and i have tested on plane text , its not a problem .
If i have to test the fastness of the cipher i got to try it on movie and audio files and check for processing time .
Is there any way i can process movie / audio files in C++ ? any primitive file format would suffice for now.

rahul8590 71 Posting Whiz

i am currently working on creating mathematical models for my research and want a non linear equation solver library which i could integrate with my program .
i searched the web and found op++ which wasnt a free program .

rahul8590 71 Posting Whiz

i would certainly try out that one.. ne ways thanks pals . all of u have been of great help .
i got the direction i wanted , i will take it from here.

rahul8590 71 Posting Whiz

i was going through many ruby books and found this amazing text editing code (its just 17 lines ) provided u use Shoes toolkit.

The code is working fine with no errors . but its only able to read (open) and input file but not save the text u wrote in the text box into a file.

Shoes.app(:width => 600, :height => 500) do
stack do
flow do
@open_button = button "Open"
@save_button = button "Save"
end
@t = edit_box :width => 0.9, :height => 400
end
@open_button.click do
@t.text = File.read(ask_open_file)
end
@save_button.click do
File.new(ask_save_file, 'w') do |f|
f.puts @t.text
end
end
end

ne idea on wats going wrong ....?

rahul8590 71 Posting Whiz

well thanks both of u guys for exchanging such arcane (atleast for me) information .
Again i am here with a stupid problem of mine .
well i got to know about pthreads and i ran a sample code for that in ubuntu 9.04 (which i installed for sake of multi threaded programs ) .

#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_THREADS	5

void *PrintHello(void *threadid)
{
   long tid;
   tid = (long)threadid;
   printf("Hello World! It's me, thread #%ld!\n", tid);
   pthread_exit(NULL);
}

int main(int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc;
long t;
for(t=0;t<NUM_THREADS;t++){
  printf("In main: creating thread %ld\n", t);
  rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
  if (rc){
    printf("ERROR; return code from pthread_create() is %d\n", rc);
    exit(-1);
    }
  }
pthread_exit(NULL);
}

And here is the output for it.

rahul $ gcc p1.c
/tmp/ccG7qvx1.o: In function `main':
p1.c:(.text+0x82): undefined reference to `pthread_create'
collect2: ld returned 1 exit status

honeslty have no idea on how this came up . Is something wrong with my PC ?

rahul8590 71 Posting Whiz

actually i just tried executiing your code and i got various errors in it.

undefined reference to `WSAStartup@8'
D:\socket programs\prog1.o(.text+0x124):prog1.cpp: undefined reference to `socket@12'
D:\socket programs\prog1.o(.text+0x13a):prog1.cpp: undefined reference to `gethostbyname@4'
D:\socket programs\prog1.o(.text+0x14d):prog1.cpp: undefined reference to `htons@4'
D:\socket programs\prog1.o(.text+0x19f):prog1.cpp: undefined reference to `connect@12'
D:\socket programs\prog1.o(.text+0x203):prog1.cpp: undefined reference to `send@16'
D:\socket programs\prog1.o(.text+0x21c):prog1.cpp: undefined reference to `recv@16'
D:\socket programs\prog1.o(.text+0x2ac):prog1.cpp: undefined reference to `closesocket@4'
D:\socket programs\prog1.o(.text+0x2b4):prog1.cpp: undefined reference to `WSACleanup@0'
Process terminated with status 1 (0 minutes, 0 seconds)

Well i am sorry , i was intending to help you , but seem like i myself have got several doubts , any idea on why is the error being displayed .?

rahul8590 71 Posting Whiz

Do you mean the 'Operating System Concepts' book by Silberschatz and Galvin? As this is what we use in our OS class

yep thats the one .

Well since i have decided to jump into this , i would be more adventurous and not confine myself to windows , so is there ne book on linux ,which can teach this thing in depth ?

rahul8590 71 Posting Whiz

the output is mentioned in my last edited post.
Well sorry for that .

I have read OS by GALVIN , but that is not suitable for pragmatic programmers like me .
can u suggest some good books which practically teaches on how to implement this and also incorporate valuable topics like IPC and MPI .

rahul8590 71 Posting Whiz

thanks guys , with ur help i could write my first thread program , but here is the problem .


i got the first program

here is the code

#include<iostream.h>
#include<windows.h>
#include<process.h>

using namespace std;

void silly (void *);

int main ()
{
    cout<<" now in main function  ";

    _beginthread( silly , 0 , (void *)12) ;

    silly ( (void *) -5 ) ;
    Sleep (100) ;
    return 0;
}

void silly ( void * arg )
{
    cout<<" this is the silly function "<< (INT_PTR)arg ;
}

i use MInGW compiler and currently working in windows

but the problem is the output was something like this

now in main function t thhisi si si sthe sitllyh ef uncstioninlly function1-2
5

honestly i dont even know whether this output is correct or not , and if this is the right one well then why is it executing so weirdly ?

rahul8590 71 Posting Whiz

i theoretically understand mutex , semaphores and the related concepts as i had a complete subject on OS this semester .
I have devised my own methods of theoretically solving dinner philosophers problem and readers/writers problems which are very well know in deadlocks
But now i want to do this thing practically , just don't have any idea on how to proceed.
I would be grateful if u could enlighten me on how to start with this.

rahul8590 71 Posting Whiz

i am ok with windows or linux .
Since i am a naive in this field i would prefer something that is basic and easy to use.

rahul8590 71 Posting Whiz

i DO have searched the google to do multithreaded programming using c++ and found there were few like the ones supported in BOOST libraries and zthreads ..
I would be glad if u guys could help me in suggesting much better ways in doing so .

rahul8590 71 Posting Whiz

Its been a while i have been writing sequential programs .
I have started working on parallel programming using C++ . Since to run those parallel programs in several machines isn't a feasible idea for me , i was wondering if there exist any parallel program simulator which executes parallel programs in single systems and give the time efficiency of the parallelized ones.

rahul8590 71 Posting Whiz

well i guess ur asking if total expenses increases more than 50,000 ..?

In that case u can just check the variable total..
Which is been calculated in line 45 of your program .

Just put a condition checking for the expense to be less than or equal to 50000 . if condition is satisfied then proceed , or give a message and exit (or whatever needful is to be done) .

rahul8590 71 Posting Whiz

Well i have been following the google OS (where in work is still going on ) for a pretty long time and when i have been through their whitepapers where they mentioned about SPDY protocol (which is an extension of TCP/IP and not to mention pretty faster than the conventional standards ) and they happen to claim to boot the whole OS in 7 seconds... (which is really very fast...! )
Will such uncanny features of google OS give a severe blow to Micro$oft windows 7 and their future os....?

rahul8590 71 Posting Whiz

please use the code tags while posting ur code , besides instead of this

for(i=0;i<5;i++)
{if(i==2)
{
for(j=0;j<4;j++)
{BL[2][j]=0;
cout<<BL[2][j]<<" ";
}

u can write it this way .

for ( j=0;j<4;j++)
b[2][j] = 0;

u can eliminate the other lines of ur code.

rahul8590 71 Posting Whiz

Well u got to show at least little bit of ur code to expect help , no ones gonna code for u from scratch.

for a start using double link list the below links can help u .
http://www.cplusplus.com/reference/stl/list/

i hope ur allowed to used STL .

rahul8590 71 Posting Whiz

may be using switch , u can give me options on wat he want to do .
And then call the corresponding functions for the option he chooses.

rahul8590 71 Posting Whiz

Well in that case , i would need to know what exactly ur trying to achieve ?

As far as i can see is that , this is a mere part of ur project or wat ever . it would be better if u could give a panaromic view on wat r u trying to do ., then it will be easier for all of us here to help u out.

rahul8590 71 Posting Whiz

this code is only to set the 3rd row to zero .
Can u post the new code where u have placed the code i wrote above ?
It would be easier for me to diagnose the problem.

rahul8590 71 Posting Whiz

a similar problem has already been asked in this forum
http://www.daniweb.com/forums/thread238596.html

i guess u will find ur answer there

rahul8590 71 Posting Whiz

Well i used to get linker errors often , when the paths weren't set.
Check ur directory ( in ur turbo c++ go to options and directories ,check whether u have given paths in include directories and the rest in it ).