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.
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.
Well it runs in MinGW and i am very happy with that , Certainly for my seminal project ideas i would keep that in mind.
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.
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 = …
-1.987582064 -1.921697293 14.35348685
-1.980833597 -1.913173814 14.14457704
-1.974314672 -1.912827834 13.93937762
-1.968764429 -1.920306829 13.73815158
-1.964819209 -1.935282114 13.54116688
-1.963024959 -1.957455651 13.34869542
-1.963848987 -1.986564664 13.16101336
-1.967690945 -2.022384383 12.97840252
-1.974892957 -2.064729167 12.80115248
-1.985748808 -2.113452266 12.62956329
-2.000512192 -2.168444412 12.46394852
-2.019403981 -2.229631421 12.30463871
-2.042618535 -2.296970913 12.15198487
-2.070329065 -2.370448236 12.00636228
-2.102692053 -2.450071663 11.86817424
-2.139850764 -2.535866836 11.73785597
-2.181937858 -2.627870463 11.61587842
-2.229077116 -2.726123197 11.50275194
-2.281384279 -2.830661633 11.39902987
-2.338967 -2.941509312 11.30531168
-2.401923891 -3.058666618 11.22224566
-2.470342647 -3.18209947 11.15053094
-2.544297199 -3.311726674 11.09091852
-2.623843875 -3.447405847 11.04421092
-2.709016509 -3.588917874 11.01126032
-2.799820469 -3.735949873 10.99296428
-2.896225564 -3.888076782 10.99025895
-2.998157807 -4.044741764 11.00410882
-3.105490067 -4.205235801 11.03549243
-3.21803164 -4.368677047 11.08538336
-3.335516873 -4.533990754 11.15472575
-3.457593033 -4.699890874 11.24440366
-3.583807714 -4.864864768 11.35520388
-3.713596205 -5.027162787 11.48777179
-3.846269398 -5.184794825 11.64256061
-3.981002938 -5.335536208 11.81977454
-4.116828532 -5.476945448 12.01930742
-4.25262844 -5.606396373 12.24067903
-4.387134341 -5.721126798 12.48297228
-4.5189318 -5.818305319 12.74477581
-4.646471576 -5.895116687 13.02413689
-4.76808883 -5.948864744 13.31853084
-4.882031053 -5.977089992 13.62485296
-4.986495027 -5.977696698 13.93943884
-5.079672538 -5.949082195 14.25811764
-5.159803788 -5.890259109 14.57630079
-5.225236577 -5.800959937 14.88910581
-5.274488517 -5.681713136 15.19151106
-5.306308787 -5.533880952 15.47853387
-5.319735444 -5.359651728 15.74542064
-5.314144201 -5.161983231 15.98783545
-5.289284816 -4.944498267 16.20203218
-5.245302028 -4.711338828 16.38499636
-5.182739019 -4.466989465 16.53454528
-5.102522814 -4.216083855 16.64937915
-5.005932467 -3.963209991 16.72908106
-4.894552294 -3.71272899 16.77406861
-4.770213486 -3.468620205 16.78550465
-4.634928202 -3.234361764 16.76517782
-4.490820495 -3.012851303 16.71536488
-4.34005824 -2.806367423 16.63868743
-4.184789729 -2.616568666 16.53797345
-4.027087786 -2.444524106 16.41613238
-3.868903342 -2.290768085 16.27604945
-3.712029482 -2.155371141 16.12050196
-3.558076132 -2.038019586 15.95209823
-3.408454892 -1.938097249 15.77323763
-3.264372968 -1.854764252 15.58608907
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 ?
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 .
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. "
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. "
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;
}
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,
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.
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.
>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;
}
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.
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.
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.
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.
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.
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.
> 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 .
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 ?
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;
}
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.
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.
I kinda understood vaguely . is there any sample program u can quote ?
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.
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 .
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.
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 ....?
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 ?
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 .?
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 ?
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 .
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 ?
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.
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.
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 .
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.
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) .
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....?
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.
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 .
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.
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.
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.
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
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 ).