kux 55 Junior Poster

Well where are you exactly using template functionalities in this code segment ??? I don't see its usage anywhere in the code given by you.

It's just a sample I made to hilight the compile error. I might use the template parameter on other methods I didn't post.

kux 55 Junior Poster

take a look at this code:

template <class T>
class C {
public:

	class A {

	protected:
		int x;
	};

	class B: public A {
	protected:
		void write() {
			cout << x << endl;
		}
	};

};

when I try to compile with g++ i get:
test.cpp: In member function ‘void C<T>::B::write()’:
test.cpp:18: error: ‘x’ was not declared in this scope

If I remove the template argument of class C all workes fine ( of course )
Does anyone have an ideea of what is going on?

thx in advance

kux 55 Junior Poster

ok, so visual C++ is not C99 compliant, but I was wondering how can I access fixed bit length integer types as the one defined in stdint.h (intN_t).

thx in advance

kux 55 Junior Poster

That's just the point that an object per se in C++ is a passive entity. It comes into being, lives and dies with the aid of a thread (or process - an active entity) only. Of course. it's possible to set a death timer then... what? It's not an object catches a timer interrupt: it's a thread!

As soon as we understand a passive nature of an object, we can fit a key to the designated problem. Possible solutions:
1. Let the guardian thread maintains a pool of mapping objects (creates, provides access to and kills them). May be, it's the only (main) thread of the application. Remember asynchronous i/o standard logic.
2. Let every such object lives itself with its own thread (process). Remember http requests and (most of) web-server standard logics.

As kux mentioned in both (and others) cases you need (more or less) well-designed access synchronization logics. That's why I said about application architecture issues.

Apropos, Sleep function does not bear a relation to the problem: it suspends the active thread, DNS server (or what else) does nothing. As usually, classic army logics does not work in this case (if you don't know what to do now, go to bed ;) )...

ok, i know this is an old thread and i'm not suppose to bring it up again, but I find this iteresting.
I posted before a method of providing a wrapper class that deletes an object after X seconds. It worked ok, …

kux 55 Junior Poster

http://en.wikipedia.org/wiki/Dynamic-link_library

just read this. It's quite well explained

kux 55 Junior Poster

Ok, i found the problem.
The CBitmap bitmap object from OnDraw(CDC*) took a handle to the bitmap and on destruction deleted the object pointed by the handle

kux 55 Junior Poster

I have a document/view aplication that opens a bitmap

I use the following OnDraw override to draw the bitmap on a window and OnOpenDocument to opening the image from file

The bitmap handle ( HBITMAP bmaphandle ) is taken from the Document object that does LoadImage in it's OnOpenDocument method
HBITMAP bmaphandle = pDoc->GetHandleToBitmap();

The problem I have is that on resizeing the window or when i move another window over it the image dissapears from the view. How do I make it persistent?

thx

BOOL CImageFilterDoc::OnOpenDocument( LPCTSTR strFilename )
{
	if ( ( m_hBitmap = (HBITMAP)LoadImage(NULL, strFilename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE) )  == NULL ) 
		return FALSE;

	return TRUE;

}

void CImageFilterView::OnDraw(CDC* pDC)
{
	CImageFilterDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: add draw code for native data here
	HBITMAP bmaphandle = pDoc->GetHandleToBitmap();
	if ( bmaphandle )
	{
		CClientDC dc(this);
		CDC *mdc=new CDC;
		mdc->CreateCompatibleDC(&dc);

		CBitmap bitmap;
		
		bitmap.m_hObject = bmaphandle;
		
		mdc->SelectObject(bitmap);
		CRect rect;
		GetClientRect(&rect);

		dc.BitBlt(0,0,rect.right,rect.bottom,mdc,0,0,SRCCOPY);

		delete mdc;

	}
}
kux 55 Junior Poster

Obviously the possible solution depends on the general architecture of your application (and run-time environment). In standard C++ an object life time defined with regard to the only execution thread and it's not a real time.

Hmm, i find this question very interesting, and as ArkM said, it's very run-time environment dependent...
I tried to implement a wrapper class that takes an dynamic allocated object and destroys it after X seconds. It uses the pthred library to create the timer in another thread

#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>

using namespace std;

class Exception {};

template < class T>
class ObjTimerWrapper
{
private:
	T* obj_;	

	int seconds_;

	pthread_mutex_t mutex;
	pthread_t timer;
	void DeleteObj()
	{
		pthread_mutex_lock( &mutex );
		delete obj_;
		obj_ = 0;
		pthread_mutex_unlock( &mutex );
	}

public:
	ObjTimerWrapper( T* obj, unsigned int seconds):obj_(obj), seconds_(seconds)
	{
		pthread_mutex_init( &mutex, 0 );
		pthread_create(&timer, NULL, ObjTimerWrapper::startTimer, (void*)this );		
	}

	~ObjTimerWrapper()
	{
		pthread_join( timer, 0 );
		pthread_mutex_destroy(&mutex);
		cout<<"destructor called"<<endl;
	}

	void Lock() { pthread_mutex_lock( &mutex ); }
	void UnLock() { pthread_mutex_unlock( &mutex ); }

	T* operator->() 
	{ 
		if ( ! obj_ ) throw Exception();
		return obj_; 
	}
	T* get() 
	{
		if ( ! obj_ ) throw Exception(); 
		return obj_; 
	}
	
	static void* startTimer(void * arg);
	
};

template < class T>
void *ObjTimerWrapper<T>::startTimer(void* arg)
{
	ObjTimerWrapper* p = (ObjTimerWrapper*)arg;
	
	sleep( p->seconds_);	
	
	p->DeleteObj();

	cout<<"timer expired, object destroyed-----------"<<endl;
	return 0;
}

class X
{
public:
	double x;
	void iterate();
	X( float xx ):x(xx){}
};

void X::iterate()
{
	for( int i = 0; …
kux 55 Junior Poster

ok, u solved your problem, but still there are some problems you should notice:

1. never put function definitions inside a header file, just the declarations. If you want to include that header in more compile units you will end up with a linker error because the compiler will generate the same code multiple times and the liker will not know what to link with.
ex:

Bla.h

class Bla { void nothing(); };

void Bla::nothing() {}; ----> THIS MUST BE PLACED IN A .CPP ( Bla.cpp )file if you want to include the header in multiple places.

2. if you have a class that has no data members(ie no state), why not make all functions static?
It makes no sense to have to instantiate an object that has no state, just to be able to call a function.
ex:
instead of
Bla obj();
obj.do_whatever();

or even worst
Bla obj = new Bla();
obj->do_whatever();
delete obj;

you can just
Bla::do_whatever();

kux 55 Junior Poster
kux 55 Junior Poster

Well, C++ is just a language, with quite a small standard library, but with A LOT of provided compilers, frameworks and third party libraries. From my point of view ( and many others, I think ) g++ is the best compiler for C++. Visual C++ is quite a generic name: it's the msvc compiler, the visual studio IDE and a library/framework that wraps winapi to build windows graphical applications( aka MFC ).
Learning Visual C++ actually means learning how to use the MFC framework and Visual Studio IDE, that, from my point of view is quite useless: 1. it costs a lot; 2. it's not portable on other os ( of course, MS policy ) 3. as far as I know Microsoft outsourced MFC
About the MSVC compiler... it generates slower machinecode than g++ and a thing I recently noticed, it doesn't quite respect the c++ standard ( thing I noticed is that exception specifications are not treated by the compiler, even if you have a throw() function that DOES throw, unexpected() is never called )
The only bright side of "Visual C++" is the Visual Studio IDE, that from my point of view is kind of the best ide right now.
If you do want to do GUI developement in C++ I would suggest using portable libraries: Qt4 or GTK++ .

About .NET's C++/CLI... This is simply not C++. It's simply another language. If you do want to develop .NET apps I would suggest learning C#.

kux 55 Junior Poster

To kux

Alas, all four text literals "mama" (for example) have different addresses (as usually). So map<char*,int> contains four different elements for the word "mama"! Obviously, it's not ok for his/her requirements. Read the original post carefully:

;)

hmm, i think you are wrong here. I mean i'm shure you are wrong here. On my STL implementation std::map has a template specialization that for char* keys uses the char* content to identify keys, not the address. Just try it. It will corectly count the words...

kux 55 Junior Poster

At first you must load map contents (where is the code? ). But you have another problem: std::map<char*,int> can't help you because its key_type is char* but operator< for char* type compares pointer values, not referred C-strings. Therefore you will get wrong dictionary...

It's possible to define a simple wrapper class for char* type with its own operator< but it seems you can't do it now. So consider map<string,int> type for your dictionary: it's less effective but a very simple solution.

Now get F1 help on map insertion (or google it) then send us the next version of the program product...

map<char*,int> is ok for he's requirements. He just has to count them, not have them in a sorted dictionary

kux 55 Junior Poster
char *stringarray[] = { "mama", "tata", "bunica", "mama", "tata", "georgel" };
	map< char*, int > mycountingmap; 
	
	for ( size_t i = 0; i < sizeof( stringarray ) / sizeof( char* ); ++i )
		++mycountingmap[ stringarray[i] ] ;

       //print result
       for ( size_t i = 0; i <  sizeof( stringarray ) / sizeof( char* ); ++i )
		cout<<stringarray[i] <<" "<< mycountingmap[ stringarray[i] ] <<" times"<<endl;
kux 55 Junior Poster

come on people, is there nobody who uses static analysis tools around here? something splint like, but for C++ not C...

kux 55 Junior Poster

ok, I've checked the forum and I don't think this topic was touched.

What I would need is an open-source or at least free static analysis tool for C++ code.
Does anybody have any suggestions? I mean, searching the web C++ lacks A LOT at this chapter, compared to Java, that has loads of tools and eclipse plug-ins for static analysis.

Looking forward to your opinion.

kux 55 Junior Poster

I would avoid using *(testScores + j) to reference a testScores array location. Use an index instead (testScore). Avoid dereferencing when possible, as horrible messes can arrise from it, when simple indexes could clean up the solution entirely.

well, i wrote the index version too. but the thing is they both mean the same thing... using an index won't protect you from going beyond the array's size...

kux 55 Junior Poster

you did not allocate memory for the int* Tests variable.

the thing is I have a

testScores = new int[numTests];

but you don't use that nowhere

Now, the thing is like this
Reading your program what you actually try to do is iterate through each student and give to him numTests marks. That means the purpose of int* Tests is to point at the start of an array of numTests elements. That means at each iteration of the outer for you need to allocate memory numTests ints in you int* Tests pointer.

Your program should look like this in oder to just work:

struct studInfo
{
char Name[31];
short Idnum;
int* Tests;
float avg;
char grade;
};

void main()
{
	short numTests, numStudents;
	studInfo* student;
	int* testScores;

	cout << "How many Students? : ";
	cin >> numStudents;
	cout << "\nHow many test scores? : ";
	cin >> numTests;

	student = new studInfo[numStudents];

	for ( int i = 0; i < numStudents; i++ )
	{
		cout << "\nEnter ID for student " << (i + 1) << ": ";
		cin >> student[i].Idnum;

		testScores = new int[numTests];

		for ( int j = 0; j < numTests; j++ )
		{
			cout << "\nEnter test score " << (j + 1) << " for student " << i + 1 << ": ";
			//put the result at tre corresponding position in the array
			cin >> *(testScores + j); //or …
skatamatic commented: Helpful +2
kux 55 Junior Poster

hmm, the thread name is kind of missguiding
this should better be "error linking to loki"
as you can see all your .o files compile fine, but the linking is the problem

did you build the Loki library?

I know Loki is mostly a template library that need not be compiled, but I think it has some parts that maybe do need to be compiled (just like boost is with it's concurrency and networking classes). Your example looks like this could be the case.

Look at the methods that you have undefined refrence to, compile the source files that they appear in, and then when you build your main.exe link to all the required object files

kux 55 Junior Poster
std::fstream BoardFile;
      BoardFile.open(arrayFileName->c_str());
kux 55 Junior Poster

u shure the library actually is at that path?

kux 55 Junior Poster

your vector has no reserved sizes, so all insertions

//option 1
	vector < vector<int> > grades;
	for(int i = 0; i < 30; i++)
	{
		vector<int> tempVec;
		for(int j = 0; j < 20; j++)
		{
			int temp;
                        myGrades>>temp;
			
                        tempVec.push_back( temp );
		}
		grades.push_back( tempVec );
	}
//option 2
	vector < vector<int> > grades( 30 );
	for(int i = 0; i < 30; i++)
	{
		grades[i].resize(20);
		for(int j = 0; j < 20; j++)
		{
			int temp;
                        myGrades>>temp;			
                        grades[i][j] = temp;
		}
	}

t

kux 55 Junior Poster

hi all,

plesae any one can send me c++ code for radix-2 Fast Fourier Transform..

my email: << email id snipped >>

:) www.google.com
enjoy

William Hemsworth commented: nice link :] +4
kux 55 Junior Poster

How can i grep a file using c++..?

I have a file. File having a keyword. i want to get the count of that.

i am tring to do
int count ;
count = system("grep -c keyword file1.txt");
cout << count ; /// this is giving me system command return value not the actual output..


how can i ghet the actual output in c++?


jujose

i think you could system("grep -c keyword file1.txt > myfile");
and then read myfile for the output.

kux 55 Junior Poster
#include <iostream>
#include <algorithm>

using namespace std;

template<class T>
class myPointer
{
public:
	T* pT_;
	int *refcount_;

public:
	myPointer(): pT_(NULL), refcount_(NULL) {};
	
	myPointer ( T* objP )
	{
		pT_ = objP;
		refcount_ = new int(1);
	}
	myPointer( const myPointer& node )
	{
		pT_ = node.pT_;
		refcount_ = node.refcount_;
		*refcount_ = *refcount_ + 1;
	}

	myPointer & operator= ( const myPointer& node )
	{
		if( this != &node )
		{
			pT_ = node.pT_;
			refcount_ = node.refcount_;
			*refcount_ = *refcount_ + 1;
		}
		return *this;
	}

	~myPointer ()
	{
		if( refcount_ != NULL )
		{
			if ( *refcount_ == 1 )
			{
				delete pT_;
				delete refcount_;
			}
			else
				*refcount_ = *refcount_ - 1;		
		}
	}
};


template < class T >
class List
{
	struct Node
	{
		myPointer<T> p_;
		Node* next_;

		Node( const myPointer<T>& obj )
		{
			p_ = obj;
			next_ = NULL;
		}


	};

	Node *head_;
public:
	List( const myPointer<T>& obj )
	{
		head_ = new Node ( obj );
	}

	void addToList( const myPointer<T>& obj )
	{
		Node * newHead = new Node( obj );
		newHead->next_ = head_;
		head_ = newHead;
	}

	void printList()
	{
		Node *p = head_;
		while ( p != NULL )
		{
			cout<< *(p->p_.pT_) << endl;
			p = p->next_;
		}
	}
	~List()
	{
		Node * p = head_;
		while ( p != NULL )
		{
			Node *paux = p->next_;
			delete p;
			p = paux;
		}
	}
};


int main(int argc, char* argv[])
{
	{
		myPointer<int> x1( new int(5) );
		myPointer<int> x2( new int(7) );
		
		List<int> …
kux 55 Junior Poster

well, this is the "good" way of doing it... of course... you could find a workarround that would kind of be based on the same principle... I'll try to make a short implementation.

kux 55 Junior Poster

http://www.onlamp.com/pub/a/onlamp/2006/05/04/smart-pointers.html?page=1

try reading this... it's kind of long, but it also explains the RAII idiom and a large variety of smart pointers.
If your STL version doesn't have std::tr1 you will probably have to install boost in order to have access to the shared_ptr, or you could just implement it yourself ( a trivial implementation is quite easy once you understand how a shared_ptr works: u just have to increase the reference count when you copy and assign the shared_ptr, decrease it in the destructor if count>1 or permanentrly destroy the pointed resource in the destructor if count = 1. )

kux 55 Junior Poster

how do you make a node of pointer of a device? (device is just a class that i made up, i need to use pointers in LL so i can "share" one object with multiple LLs)

struct node
{
  device * devicePtr;
  node * left, * right, * next;
  node(const device * dvptr)               {
              dvptr = NULL;
              left = right = next = NULL;                          }
}

then how can i access to the pointer? such as when i do a copy constructor

const list& list::operator= (const list& aList)
{
	//if self copy, don't do anything
	if(this == &aList)
		return *this;

	//release exist memory , if there's any
	if (head)
	{
		destroyList();
	}
	//make *this a deep copy of "aList"
	if(!aList.head)
		head = NULL;
	else
	{
		//copy the first node
		head = new node(aList.head->dvptr);

		node * currSrc = aList.head->dvptr;
		node * currDes = head;

		while(currSrc)
		{
			currDes->next = new node(currSrc->dvptr);
			currDes = currDes->next;

			currSrc = currSrc->next;
		}

		currDes->next = NULL;
	}
	return *this;
}

I know that aList.head->dvptr and currSrc->dvptr are wrong but i don't know how else
Can anyone point it out for me?
Thanks

there are a lot of things I don't understand in your code, or that seem wrong

struct node
{
  device * devicePtr;
  node * left, * right, * next;
  node(const device * dvptr)               {
              dvptr = NULL;
              left = right = next = NULL;                          }
}

i don't understand the node's constructor. I mean u pass to it a pointer to a device and …

kux 55 Junior Poster

Anyway, this is OS dependent, but I really can't find any other way except the looping. Another way would be to check all the interrupts at kernel level and see what system calls refer to your folder and would modify it's content, but I don't think this is legal or possible.

kux 55 Junior Poster

to solve the compilation error u have to forward the declaration of class device. That means simply add a

class device;

before you declare BST
good luck

kux 55 Junior Poster

Bullshit.

Then what are they written in ? MonkeyLanguage?

kux 55 Junior Poster

hmmm, ok, sorry, but your ideea with the file being the chatroom or whatever just isn't good !!
First of all, you have to synchronize all acces to that file. When one user is writing the file all others must wait. When one user wants to print the "chatroom" he has to transfer the whole file throug the LAN( why do this? why copy an entire file on the network when you just need the last message? ) This must also be synchronized... U just do enormous transfers with no reason. The whole design is not good.

What you have to do is do some reasearch on soket programming (linux or windows) and TCP/IP. If you do have to use a file, use it on the server as a list of subscribed users with passwords and stuff, some kind of account manager. If you find socket programming difficult you could try RPC ( the implementation would be easyer ) or even use boost ( as far as I know boost's asio, a portable wraper over sockets, similar to java's Socket class )

kux 55 Junior Poster

Could there be any better ways to determine whether a number is prime or not particularly with respect to code execution.

well, you will defenetly won't find any divisors greater then n/2 !! so, instead of iterating to n-1 you could just iterate to n/2. Another thing would be that if a number doesn't have any divizors from 2 to sqrt(n) than it will not have any above it as well, so you could just iterate from 2 to sqrt(n) .

kux 55 Junior Poster

i want to make a simple game with c++ but i really do not know how to do it:-/ ....can somebody help me to do that because i really want to know how to make a game by using c++...:?:

aaaaa, what game?

#include <iostream> //for opengl and directx support

int main( int argc, char* argv[] )
{
   cout<<"pick a number from 1 to 5"<<endl;
   int x; 
   cin>>x;
   // the AI implemented using a neet expert system model
   if( x == 2 ) 
       cout<<"you won"<<endl; 
   else 
       cout<<"you lost"<<endl;
}

Dude, just google... I don't know... : game C++. Or just get a book on the subject. There are dozens... Who do you think will make a random "simple game" right now and post u the "explained" source code when you don't even have a requirement... And even if you had one...

kux 55 Junior Poster

Sorry outright if I have posted in the wrong forum. My laptop has turned against me in the last few weeks. Ex of errors I get on a daily basis:
1. Windows internet expolorer out of memory at line 2 (sometimes 26)
2) microsoft visual ctt runtime library, runtime error (multiple sources/programs)
3) mchost.exe - application error, exception unknown, software exception
4) script error, program shutting down

I have done everything from loosen mcafee security (as it was constantly scanning every time I used IE) to compressing all old files as well as deleting programs. Even then, for example, after deframating and compressing enough files to take 2 hours, I tried to confirm my registration on this site and having 2 open browsers caused my computer to just shut down. I cannot have another window open without the whole system closing. Either I get a million error messages that cannot be closed without another opening causing my system to crash, or, more frequently, all of the sudden my programs just close and I'm staring at my desktop w/no explaination of why that just happened (for the 4-8 time that day).

I had a feeling my source of issues was with mcafee but they completely icnore my issues and just use the default solution of uninstalling/reinstalling their programs...from past experience, that is never the solution that works

Any help would be appreciated. I know I have oversteped the rules with my post but I am so overwhelmed …

kux 55 Junior Poster

of course the pointers in the structs point to the same thing. That is because you do a shallow copy. If you want the two char pointers inside the structs point to diffrent strings you need to do a deep copy ( copy the content pointed by the pointer in a and make the pointer in b point to the new content ).

kux 55 Junior Poster

yah...that's what my problem is...I cant send & receive...how can I?

It works just fine for me. I just added the followng lines to your program:
client side:

char buff[16] = "mamaaremere";
send( sockfd, buff, 16, 0 );

server side:

char buff[16];
int howmany = recv( newsockfd, buff, 16, 0 );
cout<<howmany<<" "<<buff<<endl;

just as expected... the server prints the recived message: mamaaremere

kux 55 Junior Poster

try posting the entire problem ... i mean your assignment requirements and how you thought about implementig it. Then I will probably be able to help you with it a bit more.

kux 55 Junior Poster

ok, what u posted is just the connection part.
What do you mean they don't interract? I mean, u know u have to send messages from server to client and from client to server via send, recv || write, read.

kux 55 Junior Poster

ok, long story make it short

I have a quite large project, a makefile and gnu make. All runs fine.
Trying to port the project to windows, and building with mingw32-make I come accross some problems... One of it is that i can't use sed for automatic dependeny generation as described in the gnu make manual, so I tried to find a workarround, writing a more simple automatic dependency "generator"

So, this is a dummy project:

add.h
int add ( int x, int y );

add.cpp

#include "add.h"
int add ( int x, int y) { return x+y; }

main.cpp

#include "add.h" 
#include <iostream>
using namespace std;
int main( int argc, char* argv[] )
{
	cout<<endl<<add(3,4)<<endl;
}

and the makefile:

SOURCES = main.cpp add.cpp
DEPS = main.d add.d
OBJS = main.o add.o

PRG = prg

MAKE = mingw32-make

CC = g++

.DEFAULT_GOAL: all

all:
	$(MAKE) deldep
	$(MAKE) $(PRG)

$(PRG): $(OBJS)
	$(CC) -o $(PRG) $(OBJS)
	
%.o:%.cpp
	$(CC) -c "$<" 
	
deldep:
#	rm -f $(DEPS)
	del *.d /q
	
%.d:%.cpp 
	$(CC) -E -M -MF "$@" -c "$<"

-include $(DEPS)
	
clean:
#	rm -f $(OBJS) $(PRG) $(DEPS)
	del *.d *.o prg /q

the deal is I want all .d dependency files to be recreated each time i run make. This is done via deldep target that deletes all the .d files. When all target is the dependeny files don't exist (beacause of $(MAKE) deldep ), they are created, and then the .o files and exe …

kux 55 Junior Poster

Why bother implementig your own list when you can easly use std::list and a struct Data{ string name; int value; }; with it?

kux 55 Junior Poster

But if you need a special function template to copy vector contents into array, better keep it so simple as you can, for example:

Yep, ArkM's version is better: it works for any container type. Another problem with my implementation is that I forgot to check if the vector is empty or not. If it's empty the program will crash... :(

kux 55 Junior Poster

Not so. I've blasted all of the C++ gurus on Daniweb at some point. It just happens less often because they're generally better at avoiding me.

Wow, you're so cool !!! When I grow up I want to be just like you !!! I just hope I'll be able to call myself "KUX THE GURU BLASTER, NO USE AVOIDING ME".

template <class T>
bool makearray( const vector<T> &myvec, T* &my_new_array, size_t &array_size ) throw()
{
	typedef vector<T>::value_type array_type;
	array_size = myvec.size();

	try{
		my_new_array = new array_type[ array_size ];
	}catch ( bad_alloc& )
	{
		return false;
	}

	try{
		copy ( myvec.begin(), myvec.end(), my_new_array);
	}catch(...)
	{
		delete[] my_new_array;
		return false;
	}
	return true;
}

Anyway, 4 andyT, this is a "generic" way of solving your problem. This function has 3 parameters. First is an input parameter: it takes a vector of any type. Second, is a T* reference as an output parameter. Before the call it must be an uninitialized pointer, after the call it will be a pointer to an array that will contain a copy of your vector. Don't forget to delete[] it after u use it !! Third is an output parameter: after the call, it will hold the number of elements of the new allocated array. You must know this so you know how many elements your array has, so you'll won't cause overflows.
The function returns true if the function succedes and false if not. It is guaranteed to throw no exception.

kux 55 Junior Poster
char buffer1[]="mama are mere#nu ma intereseaza\r\n";
	char buffer2[]="nu am nici un diez\r\n";

	char*p1,*p2;
	p1 = strtok( buffer1, "#");
	printf( "choped from # : %s \n", p1 );

	p2 = strtok( buffer2, "#" );
	printf( "choped from # : %s \n", p2 );

this is what I understand from your problem request.
buffer1 and buffer2 are just hardocded 4 testing, u can replace them with calls to fgets to read lines

kux 55 Junior Poster

convolute a gaussian

Just found this as for some stupid reason I had never searched the above words

http://root.cern.ch/root/html/examples/langaus.C.html

at first look..... im lost

will have a read through.....

well, that looks like an implementation... you should know if it's what u need....
if you want to test it I think you could do that with MathLab. I bet matlab has this function implemented.

kux 55 Junior Poster

ok, then give us a link with what "convolute a gaussian" means

kux 55 Junior Poster

i don't know what "convolute a gaussian" actually is... probably because I skiped my math class :) ... but, in cases like this you should do a study over the algorithm ivolved ( you could even post some links here so we can see it too ) and then try to find an open-source library that already implements your desired function ( you will shurely find it !!! ), and carefully check their implementation. If you agree with it .. there you go, if not go ahead and implement it yourself, but at least, now you have a starting point...

kux 55 Junior Poster

yea, i did a simple implementation without error checking. realloc return value is not checked, true. I did that for simplicity. And don't consider main, it's just a most simple test, no free done. If he wants it to work "fullproof", he can do that on it's own considering he understands what the function actually does.

kux 55 Junior Poster
#define ARRAYBLOCKSIZE 3

void addtoarray( int** a, size_t *length, size_t *capacity, int x, int y )
{	
	for( size_t i = 0; i < *length; i++ )		
		if ( (*a)[i] == x )
		{
			if ( *length == *capacity )
			{
				*a = ( int* ) realloc ( 
                                        *a, ( *capacity + ARRAYBLOCKSIZE ) * sizeof(int) );
				*capacity = *capacity + ARRAYBLOCKSIZE;
			}

			(*length)++;
			for( size_t j = *length - 1; j > i; j--  ) (*a)[j]= (*a)[j-1];
			(*a)[i] = y;
			break;
		}			
}

int main(int argc, char* argv[])
{
	size_t capacity = ARRAYBLOCKSIZE;
	int *myarray = (int*)malloc(sizeof(int)*ARRAYBLOCKSIZE);
	myarray[0]  = 0;
	myarray[1] = 1;
	
	size_t length = 2; // => array has one empty slot

	addtoarray( &myarray, &length, &capacity, 1, 5 ); //now length == capacity
	addtoarray( &myarray, &length, &capacity, 9, 7 ); //realloc => capacity = 6
	addtoarray( &myarray, &length, &capacity, 5, 7 );
	printf( "length and capacity are: %d, %d\n", length, capacity );
	for( size_t i = 0; i < length; i++ )
	{
		printf( "array[ %d ] = %d\n",i ,myarray[i] );
	}
}

this is your function
things to note:
-u provide a pointer to the array, pointer to the number of filled array comonents , pointer to it's capacity and the two numbers x and y.
-If the array is full ( lenght == capacity ) then realloc is used to extend it's capacity
- ARRAYBLOCKSIZE is 3 for exemplification. it should be a big value so realloc is called not so often

kux 55 Junior Poster

just use the vector constructor that takes 2 iterators as parameters

vector<int> vectorOfInts ( current , current + 10 );

if u're vector is allready constructed u could

vectorOfInts.assign( current, current + 10 );

if u want to append

copy( current, current + 10, back_inserter( vectorOfInts ) );