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

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

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

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

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

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

I think I understand what u mean.
I remember the old days when I was doing a simple "snake" game in pascal.
Back then I was able to do something like

repeat
repeat
.......move snake in one direction.....
until keypressed();
..... process input key and change dirrection....
until forever

or something like it... The thing was that the snake was moving ( implemented in the loop ) and when an arrow key was pressed the direction would heve been changed. Ok, the only problem is that i don't know any standard C function that would do the samething thing as keypressed in pascal. The only alternative I can think about is having another thread that listens to user input, push the event in a global queue and have the "game running" thread process the event queue with user input. This is a more general approach, but I'm still wondering if C has any function like keypressed() :) . So if anybody can enlighten me... :)

kux 55 Junior Poster

hi guys,

i have declared a char pointer. i am using this in itoa() function to convert integer data into hex data e.g

char * hexData= NULL;
             itoa(1484820,hexData,16);

this results in equalent of 1484820 in hex decimal and store it in hexData.

now when I want to some process in hexData(char pointer). when I pass it to my function for further process, the value of hexData(char pointer is changed now contains garbage) see the code below

main()
{
char * hexData=NULL;
itoa(148420,hexData,16);
printf("%s",hexData);---------------------//output is 243C4
writeinFile(hexData,fptr);
}

writeinFile(char* str, FILE *fptr)
{

printf("%s",hexData);---------------------//output is 2434C but some time a garbage value
char *hex = new char[30];
printf("%s",hexData);---------------------//output is always garbage value after any new   
                                                          //char *pointer declaration.

----
----
----
}

}

I am confused whats problem going on here.
can any tell me its solution?


Asif

well, hexData points to unallocated memory ...
use:
char hexData[BUFFSIZE];
or
char * hexData = (char*)malloc( BUFFSIZE* sizeof( char));

u get garbage because u use unallocated memory that can be overwritten at any time

kux 55 Junior Poster

yea, and when writting the assignment operator=, don't forget the assignemt to self problem

kux 55 Junior Poster

Hi, I would like to ask you for help in converting this code from C to C++. It's my little friend 's homework, but I can't help him 'cause I know nothing about C :( In fact, I just can't figure the "scanf" part out, I think the other part is similar to C++. Thanks in advance !
[
#include <stdio.h>
#include <string.h>
void main()
{
int i,br=0,d=0;
char r[200];
printf("Vnesete Recenica\n");
gets(r);
d=strlen(r);
for(i=0;i<=d;i++)
{
if((r=='n')&&(r[i+1]=='o'))
{
r=' ';
r[i+1]=' ';
br++;
}
}
printf("Vo Vasata recenica se pronajdeni i izbrisani %d no zborovi\n",br);
scanf("%d",&i);
}

]

#include <iostream>
#include <string>

void main()
{
	int i,br=0,d=0;
	//char r[200];
	std::string r;
	//printf("Vnesete Recenica\n");
	std::cout<<"Vnesete Recenica\n"<<std::endl;
	//gets(r);
	std::cin>>r;
	//d=strlen(r);
	//for(i=0;i<=r.length();i++)
	/*
	for(i=0;i<r.length() - 1 ;i++) //THIS WAS INCORRECT IN THE 1st IMPLEMENTATION  TOO, BUFFER OVERRUN !!
	{
		if((r.at(i)=='n')&&(r.at(i+1)=='o'))
		{
			r[i]=' ';
			r[i+1]=' ';
			br++;
		}
	}
	*/
	std::string::size_type poz = -1;
	while ( true )
		if (  ( poz = r.find( "no", poz + 1 ) ) != std::string::npos )
			br++;
		else 
			break;
	

	//printf("Vo Vasata recenica se pronajdeni i izbrisani %d no zborovi\n",br);
	std::cout<<"Vo Vasata recenica se pronajdeni i izbrisani "<<br<<" no zborovi\n"<<std::endl;
	//scanf("%d",&i);
	std::cin>>i;
}

the last scanf/cin is placed there so that the program won't end untill the user sees the output and presses some key.
I placed the old C implementation between coments. It …