karthik.c 6 Light Poster

did you try:

int i=0;
int ch=recv(new_socket,(void*)&i,sizeof(int),0);
printf("Value of a is :%d\n", i);

thanx programmersbook ,it worked !!

first of all sorry,as instead of posting this ques in C-Forum i posted in C++ ...

i cant understand what is wrong in my approach of receiving the datas in the recv(),as i declare one void pointer and typecast it to approp pointer before dereferencing and it worked for quite a no of times and then it was not workin..
so,is my way of getting datas using pointers is wrong?


if i go by ur way, can u plz xplain how come "&i" (where i is a local variable in server code) get the value from client side or how value is passed from client's send() to server's recv().

thanx !!

karthik.c 6 Light Poster

hi,
im getting recv:bad address error in the server code when im receiving the data from the client.i tried passing the structure and an integer alone ,but for both i got the same error.

for structures:
client:

struct Data
        {
                char data1[255];
                char data2[255];
                int val1;
       };
struct Data myData = { "Let us C", "YPK", 101 } ;
int ch = send(create_socket,&myData,sizeof(struct Data), 0);
struct Data
                {
                        char data1[255];
                        char data2[255];
                        int val1;
                };
void *dptr1;
struct Data *dptr;
struct Data *dptr = (struct Data*)(dptr1);
printf("The Elements of structure \n");
printf("Book- %s Author- %s Code- %d\n",dptr->data1,dptr->data2,dptr->val1);

for integer data:
client:

int a=5;
int ch = send(create_socket,&a,sizeof(int), 0);

server:

void *ptr;
 int *iptr;
int ch=recv(new_socket,ptr,sizeof(int),0);
iptr = (int*)(ptr); 
printf("Value of a is :%d\n",*iptr);
karthik.c 6 Light Poster

hi guys im tryin to do a java client / c++ server socket program .in the java client program i serialize the object and pass them over socket to c++ server.now when im gettin them in c++,im not able to deserialize it properly as i tried for binary serialization since c++ does not support object serialization.but it didnt work out properly,as when im printin the member variables of c++ class im gettin junk values.i did came across many libraries like Boost which supports serialization but was not sure whether it will deserialize a java object.

so what if my approach for dis problem is right or shud i go for JNI or any other concepts.if its in JNI then i fear my c++ server 'ill be loaded as shared library file along with java file at runtime which i think 'ill not be a right way to do client-server socket program.

my java client code:

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

public class KnockKnockClient
{
	public static void main(String[] args) throws IOException
	{
		Socket kkSocket = null;
		ObjectOutputStream oos=null;
		Sample s;
		String str="hello dude";
	
		try{
            		kkSocket = new Socket("localhost", 4455);
			oos = new ObjectOutputStream(kkSocket.getOutputStream());
        	}
		catch (UnknownHostException e)
		{
            		System.err.println("Don't know about host: 192.168.1.137.");
            		System.exit(1);
        	}
		catch (IOException e)
		{
            		System.err.println("Couldn't get I/O for the connection to: 192.168.1.137.");
            		System.exit(1);
        	}
		s=new Sample();
		
		oos.writeObject(str);
		
		System.out.println("name :" + s.name);
                System.out.println("age  :" + s.value);
                kkSocket.close();
    }
}

class Sample implements Serializable
{
	String name="xyz";
	int value=10;
}

my c++ server …

karthik.c 6 Light Poster

hi guys i tried to read object from a file in cpp using ifstream object like given below:

c++ server:

#include <iostream> 
#include <fstream>
#include <string>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<sys/stat.h>
#include<fcntl.h>

using namespace std;
class Data
{	
	public:
		char data1[255];
		char val1[255];
};
	
int main()
{
	  int create_socket,new_socket,fd;
	  socklen_t addrlen;
	  struct sockaddr_in address;

	if ((create_socket = socket(AF_INET,SOCK_STREAM,0)) > 0)
    	cout<<"The socket was created\n";
  	address.sin_family = AF_INET;
  	address.sin_addr.s_addr = INADDR_ANY;//INADDR_ANY;inet_addr("localhost");
  	address.sin_port = htons(4000);
  	cout<<"\nworking";

  	if (bind(create_socket,(struct sockaddr *)&address,sizeof(address)) == 0)
    	cout<<"Binding Socket\n";

  	listen(create_socket,3);
  	addrlen = sizeof(struct sockaddr_in);

	cout<<"*************************\n";
  	new_socket = accept(create_socket,(struct sockaddr *)&address,&addrlen);
	cout<<"*************************\n";

	//char buf[1024];
	//Data *d=new Data;
	Data dobj;
	if (new_socket > 0)
	{
     		cout<<"The Client "<<inet_ntoa(address.sin_addr)<<" is Connected...\n";//inet_ntoa(address.sin_addr));
		int ch = recv(new_socket,&dobj,1023,0);
		perror("recv");
		cout<<"Status = "<< ch<<"\n";	
		ifstream in("binary.txt", ios::binary);
		in.read((char*)&dobj, sizeof(dobj));

		if(ch !=-1)
		{
			//buf[ch]='\0';
			//printf("Client: received %s\n",buf);
			cout<<"Client: received "<<dobj.data1<<"\n";
			cout<<"Client: received "<<dobj.val1<<"\n";
			cout<<"Request Completed\n";
			
		}
		else
		perror("recv");
	}
	else
	{
		cout<<"Client not connected ...\n";
	}  	
		close(new_socket);
  		return close(create_socket);

}

but this is not workin and its o/p was like dis:

The socket was created

workingBinding Socket
*************************
*************************
The Client 127.0.0.1 is Connected...
recv: Success
Status = 60
Client: received {
Client: received �
Request Completed

i did googled for this and i came to know that c++ does not support / n does not have any standard libraries for object serialization but does support binary serialization which i have done above.also i came across BOOST c++ libraries and …

karthik.c 6 Light Poster

hi guys ,im trying to send serialized php object to c++ server. i dont have clear idea if it is possible to deserialize the php object in c++ code.i dont know how to convert it into c++ object and get the value out of it.

when im running the server and client ,the O/P is like this:
c++ server:

The socket was created
workingBinding Socket
The Client is Connected...
recv: Success
Status = 60
Client: received O:4:"data":2:{s:1:"b";i:60;s:6:"string";s:11:"Hello World";}
Request Completed

php client:

Socket created ...
Socket connected ...
serialized object : O:4:"data":2:{s:1:"b";i:60;s:6:"string";s:11:"Hello World";}
This is my buffer
sent 60 bytes from socket_send(). Closing socket...

php client :

<?php

	set_time_limit (0);
	$address = 'localhost';//'192.168.1.93';
	$port = 4000; 
        // Create the socket
        if(($sockd = socket_create(AF_INET, SOCK_STREAM,SOL_TCP))<1)
		die("Unable to create socket:" . socket_strerror(socket_last_error()));
	else
		echo "Socket created ...\n";
 
        if(socket_connect($sockd,$address,$port) == FALSE)
                die("Unable to connect:" . socket_strerror(socket_last_error()));
	else
		echo "Socket connected ...\n";
 
        $buffer =" This is my buffer";
 
	class data
	{
		var $b = 60;
		var $string ="Hello World";
	}
	$obj1 = new data(); 
	echo "serialized object : " . serialize($obj1) . "\n";
        //if(socket_send($sockd, $buffer,1024,MSG_WAITALL) == false))
	//if (false != ($bytes = socket_send($sockd, $buffer, 1024, MSG_WAITALL)))
	if(($bytes=socket_send($sockd,serialize($obj1),1024, MSG_WAITALL))==false)
	{
                die("Unable to connect:" . socket_strerror(socket_last_error()));
 	}
	else
	{
		echo "$buffer \n";
		echo "sent $bytes bytes from socket_send(). Closing socket...";
	}
        unset($obj1);
 
      //if(($buffer = socket_read($sockd, 1024)) == FALSE)
                //die("Unable to read from socket:" .   socket_strerror(socket_last_error()));
 
        socket_close($sockd);
 ?>

c++ server:

karthik.c 6 Light Poster

salem im not that good in pointers and have only vague idea about using it ,so i think i have no other option other than to pass them(structure and map) as void *.
if you think there are other possible ways to get them inside this function please let me know.

thanx

karthik.c 6 Light Poster

ok salem if it is so then why compiler is showing the same error when i write like this:

Map->insert(make_pair(structPtr.Msisdn,structPtr));

i've also included how i've declared everything,so that you may get where im going wrong...
i wrote my structure declaration like this:

typedef struct _HomeNwSt
{
        std::string Msisdn;
        int   NwId;
}HomeNwSt;

map &map iterator declaration :

map<std::string,HomeNwSt> HomeMap;
map<std::string,HomeNwSt>::iterator it;

make_pair typedef :

typedef std::pair <std::string,void *> make_pair;

but in the function in which im trying to insert fields into map ,im passing this entire structure and map as void * parameters like this:

int get_map(Ndb * myNdb,char * tableName,char * field,void * structPtr,void *Map)

thanx

karthik.c 6 Light Poster

ok sure i'll read about it ,but can you tell me how to cast it to correct type,as i did also tried:

Map->insert(make_pair((std::string)structPtr.Msisdn,structPtr));

but was showing the same error...

thanx

karthik.c 6 Light Poster

hi salem,i have changed char array fields into std::string in structure declaration ,i also changed the same in map & map iterator declaration.now i tried above code like this :

Map->insert(make_pair(structPtr.Msisdn,structPtr));

but it was showing error like this:
NDBAPI/NdbApi.cpp:157: error: `void*' is not a pointer-to-object type
NDBAPI/NdbApi.cpp:157: error: request for member `Msisdn' in `structPtr', which is of non-class type `void*'
salem i've doubt how std::string would allocate memory space for the equivalent of
char[20] Msisdn;
by declaring
std::string Msisdn;
without specifying the size we need or does it allocate at runtime?
sorry to say that i dont need to write the below code:

if(strcmp(std::string((char *)structPtr.Msisdn),field)==0)

as for my functionality it is wrong to check.so i deleted those lines.

karthik.c 6 Light Poster

hi salem based on your comment i used std::string and tried to typecast it into correct type like this-

if(strcmp(std::string((char *)structPtr.Msisdn),field)==0)
                {

                        Map->insert(make_pair(std::string((char *)structPtr.Msisdn),structPtr));
                }

in the above code i know that im converting the entire structure into char * which makes the other int field in the structure also char * because of which im gettin the same error again.im getting stuck here as i dont know exactly how to typecast here and get the correct value ,so if u could help me out here it would be great.

thanks

karthik.c 6 Light Poster

hi one correction in the above code,in the HomeNwList.cpp,inside the for loop it is actually :

for( it = HomeMap.begin(); it != HomeMap.end(); it++)

it is not

for( it = HomeNwList.begin(); it != HomeNwList.end(); it++)
karthik.c 6 Light Poster

hi ,when im trying to insert key-value pair in map(key-char array field of a structure,value-entire structure)im having errors .

NDBAPI/TGBitsNdbApi.cpp: In function `int get_map(Ndb*, char*, char*, void*, void*)':
NDBAPI/TGBitsNdbApi.cpp:154: error: request for member `Msisdn' in `structPtr', which is of non-class type `void*'
NDBAPI/TGBitsNdbApi.cpp:156: error: `void*' is not a pointer-to-object type
NDBAPI/TGBitsNdbApi.cpp:156: error: request for member `Msisdn' in `structPtr', which is of non-class type `void*'
NDBAPI/TGBitsNdbApi.cpp:156: error: `make_pair' was not declared in this scope
TGBitsNdbApi.cpp

#include "TGBitsNdbApi.h"
#include <map>
......
......
int get_map(Ndb * myNdb,char * tableName,char * field,void * structPtr,void *Map)
{
	const NdbDictionary::Dictionary* myDict= myNdb->getDictionary();
        const NdbDictionary::Table *myTable= myDict->getTable(tableName);
        if (myTable == NULL)
                APIERROR(myDict->getNdbError());
	 const NdbDictionary::Index *myIndex= myDict->getIndex("index1",tableName);
	if(myIndex == NULL)
	APIERROR(myDict->getNdbError());

	NdbTransaction *myTransaction= myNdb->startTransaction();
        if (myTransaction == NULL) APIERROR(myNdb->getNdbError());

        NdbIndexOperation *myIndexOp= myTransaction->getNdbIndexOperation(myIndex);
        if (myIndexOp == NULL) 
	{
			std::cout << myTransaction->getNdbError().message << std::endl;
			myNdb->closeTransaction(myTransaction);
			return -1;
	}

	if(myIndexOp->readTuple(NdbOperation::LM_Exclusive) != 0)
	{
			std::cout << myTransaction->getNdbError().message << std::endl;
			myNdb->closeTransaction(myTransaction);
			return -1;
	}
	else
	{
		if(strcmp(structPtr.Msisdn,field)==0)
		{
			Map->insert(make_pair(structPtr.Msisdn,structPtr));//im gettin error in this line
		}
        }
......
......

TGBitsNdbApi.h

#ifndef TGBITSNDBAPI_H_
#define TGBITSNDBAPI_H_
....
....
typedef pair<char *,void *>make_pair;
....
....

HomeNwList.cpp

int main(int argc, char** argv)
{
      .....
      .....
        HomeNwSt homeNwSt;
	map<char *,HomeNwSt> HomeMap;
	map<char *,HomeNwSt>::iterator it;
        int val=get_map(Ndb * myNdb,char * tableName,char * field,(void *)&homeNwSt ,(void*)&HomeMap)
	      if(val==-1)
              ........
              ........
	for( it = HomeNwList.begin(); it != HomeNwList.end(); it++)
	   {
		
		HomeNwSt obj = (*it).second;
                std::cout << "col 1: "<< obj.NwId << "\t";
                std::cout << "col 2: "<< obj.Msisdn << "\t\n";
	   }
	return 0;
}
karthik.c 6 Light Poster

hi guys,ive changed the above coding to make it work with no problem while inserting ,deleting,searching which i said before ,but now im facing one new problem of segmentation fault while opting for exit operation and the error was like this:

Program received signal SIGSEGV, Segmentation fault.
0x092330a8 in ?? ()
which gives me no clue as where it is occuring or what triggers this segmentation fault.
this error is not frequent every time,as it occurs mostly after deleting some nodes in trie or emptying the trie.
any help would greatly be appreciated thanx...

karthik.c 6 Light Poster

Partition Magic is another good tool for this. $$

i've tried partition magic s/w for resizing the hard drive space(which contained datas) which i already created and and it worked fine .The only problem is that it names the drive by itself i.e it gives D: for CD/DVD drive by default which we cant change i suppose.

karthik.c 6 Light Poster

thanks jephthah for taking your time to read my code . i've enclosed a link to upload a pdf file which explains the concept of patricia trie and i started doing code based on this concept.because of some problem i was not able to attach that pdf here,so it would be great if anyone can go through it and help me where my logic is going wrong .patricia trie is explained in page no-573 with few examples for insertion and deletion.

http://www.4shared.com/dir/11076492/4525eace/sharing.html

thanks

karthik.c 6 Light Poster

im able to compile and run the above program without any warning/error using the same above pat.c file.problem arises when i try to insert/delete i.e sometimes it is not acceptin more than 2/more values and sometimes it is showing the key not present in tree as deleted.when i debugged using gdb,it skipped some of the lines to print those wrong output.im not getting why it is skipping those lines.

karthik.c 6 Light Poster

when you build your program and it complains: "warning: implicit declaration of function `memset'" ... you have to pay attention to that.

memset() and memcmp() require that you #include <string.h>

theres could be other issues, but start with that and lets see what happens.


.

actually i didnt get the warning what you are saying and im actually passing two int * argument(and so im not passing any strings here) in memcmp() function instead of passing void *, which can relate to any datatype. so will that be a problem?
i did tried your suggestion by including string.h,but still the problem remains while inserting/deleting.

karthik.c 6 Light Poster

hi again,i've modified the above coding for pat.c and now im not getting any segmentation stack problem,but im stuck with logical error i.e im not able to insert /delete properly .it would be great if someone could help me out.thanks
pat.c

#include<stdio.h>
#include<stdlib.h>
#include "pat.h"


static NCS_PATRICIA_NODE *search(NCS_PATRICIA_TREE *const pTree,int* key)
{
   NCS_PATRICIA_NODE *pNode;
   NCS_PATRICIA_NODE *pPrevNode;

   pNode = (NCS_PATRICIA_NODE *)&pTree->root_node;

   do 
  {
      pPrevNode = pNode;

      if (m_GET_BIT(key, pNode->bit) == 0)
      {
         pNode = pNode->left;
      }
      else
      {
         pNode = pNode->right;
      
      }	
   }while (pNode->bit >  pPrevNode->bit);

   return pNode;
}

int ncs_patricia_tree_init(NCS_PATRICIA_TREE *const pTree,const NCS_PATRICIA_PARAMS *const pParams)
{
   if (pParams == NULL)
      return 0;

   if (  (pParams->key_size < 1)
         ||(pParams->key_size > NCS_PATRICIA_MAX_KEY_SIZE) 
      )
   {
      return 0;
   }

   pTree->params = *pParams;

   /* Initialize the root node, which is actually part of the tree structure. */
   pTree->root_node.key_info =0;
   pTree->root_node.bit = -1;
   pTree->root_node.left = 
   pTree->root_node.right = &pTree->root_node;
   if ((pTree->root_node.key_info= malloc(sizeof(pTree->params.key_size)))== NULL)

   {
      return 0;
   }

   memset(pTree->root_node.key_info, '\0',pTree->params.key_size);
   pTree->n_nodes = 0;

   return 1;
}


int ncs_patricia_tree_add(NCS_PATRICIA_TREE *const pTree,
                                  NCS_PATRICIA_NODE *const pNode)
{
   NCS_PATRICIA_NODE *pSrch;
   NCS_PATRICIA_NODE *pTmpNode;
   NCS_PATRICIA_NODE *pPrevNode;
   int bit;

   pTmpNode = search(pTree, pNode->key_info);
   if (m_KEY_CMP(pTree, pNode->key_info, pTmpNode->key_info) == 0)
   {
      return 0;  //duplicate!. 
   }
   else	 
   {	
   bit = 0;

   while (m_GET_BIT(pNode->key_info, bit) ==
          ((pTmpNode->bit < 0) ? 0 : m_GET_BIT(pTmpNode->key_info, bit)))
   {
      bit++;
   }

   pSrch = &pTree->root_node;

   do 
   {
      pPrevNode = pSrch;
      if (m_GET_BIT(pNode->key_info, pSrch->bit) == 0)
         pSrch = pSrch->left;
      else 
         pSrch = pSrch->right;
   } while ((pSrch->bit < bit) && (pSrch->bit > pPrevNode->bit));

   pNode->bit = bit;

   if (m_GET_BIT(pNode->key_info, bit) == 0)
   {
      pNode->left …
karthik.c 6 Light Poster

if you are programming in linux ,then debug the program using gdb or some other debugger and find out where segementation fault problem is occuring.

karthik.c 6 Light Poster

@above code-there is no need to put any open/close paranthesis iniside each case statements...

karthik.c 6 Light Poster

hi guys im trying to code patricia trie in c using gcc and when i debuged the program im gettin segmentation stack problem in search function of it.im not sure why it is showing and i've included pat.c,pat.h and ncspatricia.h files.
i also want to know what is the difference if we assign a variable as int and as unsigned int8 or 32.
the error was in the following line:
Program received signal SIGSEGV, Segmentation fault.
0x080484d4 in search (pTree=0x804a008, key=0x64) at pat.c:26
26 }while (pNode->bit > pPrevNode->bit);

im not able to access the pNode->bit after checking above condition but no problem before checking this condition,as it shows the following error after checking the condition:
(gdb) p pNode->bit
Cannot access memory at address 0x0
before:
(gdb) p pNode->bit
$3 = -1
im also not able to print the below value (line 168 of main())and im not sure about why is it so?
//printf("%d",pNode1->key_info);

pat.c

#include<stdio.h>
#include<stdlib.h>
#include "pat.h"


static NCS_PATRICIA_NODE *search(NCS_PATRICIA_TREE *pTree,int *key)
{
   NCS_PATRICIA_NODE *pNode;
   NCS_PATRICIA_NODE *pPrevNode;

   pNode = (NCS_PATRICIA_NODE *)&pTree->root_node;

   do 
  {
      pPrevNode = pNode;

      if (m_GET_BIT(key, pNode->bit) == 0)
      {
         pNode = pNode->left;
      }
      else
      {
         pNode = pNode->right;
      
      }	
   }while (pNode->bit >  pPrevNode->bit);

   return pNode;
}

int ncs_patricia_tree_init(NCS_PATRICIA_TREE *pTree,const NCS_PATRICIA_PARAMS *const pParams)
{
   if (pParams == NULL)
      return 0;

   if (  (pParams->key_size < 1)
         ||(pParams->key_size > NCS_PATRICIA_MAX_KEY_SIZE) 
      )
   {
      return 0;
   }

   pTree->params = *pParams;

   /* Initialize the root …
jephthah commented: thanks for properly formatting code, and including enough info to reproduce. +6
karthik.c 6 Light Poster

thanx a lot mcriscolo,your explanation was satisfactory ...but i would also like to know if there is any sequential order by which rules defined in the makefile are evaluated or it doesnt matter here in this file?

karthik.c 6 Light Poster

hi mcriscolo, i tried your make file and its working fine without any problem,but still i've some doubts in it to clarify...
>>The other major addition is the ".cpp.o" rule to build the objects prior to linking the executable.

$(BINARY):      $(OBJS)
        $(CPPCOMPILER) -o $(BINARY) $(OBJS)

the above rule is what which links all the object files to produce executable ,but you have included .cpp.o rule for creating object file only after the target rule and makfile is running fine without any problem(even though i tried other way by writting .cpp.o rule before target rule and as expected it didnt show any error there also)so why is that it is not showing any error?

>>I found that the one rule in the original Makefile was not picking up the stuff in COMPILERFLAGS, so I knew it was hitting a default rule for the .cpp items.

>>but then the variables for the object files that have the paths pre-pended would fail during the link step. I fixed that by performing a "cd $(S_DIR)" prior to the compile step to drop the *.o files in the "source" folder.

im sorry if i sound stupid but still cant help asking you,i didnt get what you was saying here and also i'vent used .cpp.o rule till now ...and when i've created .o files already using the suffix replacement like this:

OBJS = $(SOURCES:.cpp=.o)

why should i use .cpp.o rule again for creating object files?so can you explain me …

karthik.c 6 Light Poster

hi mcriscolo ,im sorry i actually misplaced 'ls' in the SOURCES and HEADERS path but later when i gave make command it showed some errors like this:

[root@localhost makedemo]# make
g++ -c -o /root/workspace/source/Main.o /root/workspace/source/Main.cpp
/root/workspace/source/Main.cpp:1:24: SourceData.H: No such file or directory
/root/workspace/source/Main.cpp:2:22: TestFile.H: No such file or directory
/root/workspace/source/Main.cpp: In function `int main()':
/root/workspace/source/Main.cpp:5: error: `TestFile' was not declared in this scope
/root/workspace/source/Main.cpp:5: error: expected `;' before "obj"
/root/workspace/source/Main.cpp:6: error: `SourceData' was not declared in this scope
/root/workspace/source/Main.cpp:6: error: expected `;' before "sd"
/root/workspace/source/Main.cpp:7: error: `sd' was not declared in this scope
/root/workspace/source/Main.cpp:9: error: `obj' was not declared in this scope
make: *** [/root/workspace/source/Main.o] Error 1

im sure i've no problem in other header and source files as i compiled and ran successfully when all was in the same folder(including makefile).

i've used makedepend tool for dependency and i think above problem is arising because of dependency issue.i would also like to know where(in which folder) .o files will be created when im compiling ?

any way i've also included source and header file coding here...
source:
Main.cpp:

#include "SourceData.H"
#include "TestFile.H"
int main()
{
TestFile obj;
SourceData sd;
sd.rollNum = 101;
sd.name = "Shiva";
obj.Display(sd);
return 0;
}

TestFile.cpp:

#include <iostream>
#include "TestFile.H"
void TestFile::Display(SourceData &d)
{
        std::cout<<d.ToString()<<std::endl;
}

Header:
SourceData.H

#ifndef _SORCEDATA_H_
#define _SORCEDATA_H_
#include <iostream>
#include <sstream>
#include <string>
struct SourceData
{
int rollNum;
std::string …
karthik.c 6 Light Poster

hi mcriscolo ,im still having problem after changing it to the way u have told..
error was like this:
[root@localhost makedemo]# make
/bin/sh: /root/workspace/source/: is a directory
/bin/sh: /root/workspace/source/: is a directory
g++ -W -Wall -I. -o output
g++: no input files
make: *** [output] Error 1

karthik.c 6 Light Poster

hi guys im trying to write a makefile which contains :two cpp files and two header files.
now i've put cppfiles in a folder called source whose path is: /root/workspace/source

and header files in a folder called header whose path is:
/root/workspace/makedemo/header

my makefile is in the path:/root/workspace/makedemo

my makefile was like this:

HEADERS = $(shell /root/workspace/makedemo/header ls *.h)
SOURCES = $(shell /root/workspace/source ls *.cpp)

COMPILERFLAGS = -W -Wall
DEBUGFLAGS = -g
CPPCOMPILER = g++

INCLUDES = -I.


OBJS = $(SOURCES:.cpp=.o)

BINARY = output

all: $(BINARY)

$(BINARY): $(OBJS)
        $(CPPCOMPILER) $(COMPILERFLAGS) $(INCLUDES) -o $(BINARY) $(OBJS)
depend:
        makedepend -f- -- $(SOURCES) > .depend_file
clean:
        rm -rf *.o .depend_file $(BINARY) *~

#DO NOT DELETE

im sure that i've given the correct path but it is showing errors like this:

[root@localhost makedemo]# make
/bin/sh: /root/workspace/source: is a directory
/bin/sh: /root/workspace/source: is a directory
g++ -W -Wall -I. -o output
g++: no input files
make: *** [output] Error 1

any help appreciated...

karthik.c 6 Light Poster

hi shibukumar, i actually was trying to program the code which was given in a site where they are using hash_map at the same time they are also saying hashtable Datastructure is not part of c++ standard library.

http://www.tenouk.com/Module29a.html
so what if their is any way to do it??

karthik.c 6 Light Poster

hi again,im having some problem while coding with hash_map
my coding was like this:

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

int main()
{
        typedef pair<int,int>make_pair;
        hash_map<int,int>::iterator hmp0_iter;

        hash_map<int,int>hmp0;

        hmp0.insert(make_pair(1,78));
        hmp0.insert(make_pair(3,34));

        for(hmp0_iter=hmp0.begin();hmp0_iter!=hmp0.end();hmp0_iter++)
        {
                cout<<(*hmp0_iter).second<<' ';
        }
        cout<<endl;

        return(0);
}

error was like this:
hashdemo.cpp:2:19: hash_map: No such file or directory
hashdemo.cpp: In function `int main()':
hashdemo.cpp:8: error: `hash_map' was not declared in this scope
hashdemo.cpp:8: error: expected primary-expression before "int"
hashdemo.cpp:8: error: expected `;' before "int"
hashdemo.cpp:10: error: expected primary-expression before "int"
hashdemo.cpp:10: error: expected `;' before "int"
hashdemo.cpp:12: error: `hmp0' was not declared in this scope
hashdemo.cpp:15: error: `hmp0_iter' was not declared in this scope

but when i replaced #include<hash_map>with #include<hash_map.h>the program ran and printed the output but it did showed some warnings saying im using deprecated header.

im workin in linux using gcc(version3.4.6)so does it support hashmap??

karthik.c 6 Light Poster

hi again ,suppose if i want to connect to another m/c(server) in LAN from my m/c (client)and print the contents of a file in that(server)m/c by specifying the path of that file can i do so using tcp ??
can any one help me in writting code for reading file and printing it after getting connected to server and also i want to know how to specify clients and server's ip-address for connecting i.e do i need to give while compiling the client/server program as in C or do i need to include it in the program itself (if so where should i include that)??

karthik.c 6 Light Poster

thanks narue ,i tried out both ways of inserting:using pair object and operator overload and program is working fine.

karthik.c 6 Light Poster

hi guys, im trying to do map in cpp using STL and when i ran a simple program it was showing error that:
error:
nomatchfor'operator<<'in'std::cout<<(&mp0_iter)->std::_Rb_tree_iterator<_Tp>::operator* [with _Tp = std::pair<const int, int>]()'....
my program was like this:

#include<map.h>
#include<iostream.h>

int main()
{
        map<int,int>::iterator mp0_iter;
        map<int,int>mp0;
        map<int,int>mp1;

        mp1.insert(1,13);
        mp1.insert(2,16);
        mp1.insert(3,17);

        for(mp0_iter=mp1.begin();mp0_iter!=mp1.end();mp0_iter++)
                {
                        cout<<*mp0_iter<<' ';
                }
        cout<<endl;

        return(0);
}
karthik.c 6 Light Poster

hi ancient dragon ,first of all im really sorry for making a stupid statement that file is in client m/c and i should 've been careful before posting it.here goes the scenario...

i expect the file to be in server m/c and im sure that i've given the correct path for that file from the client m/c and im(client) asking server to print the contents of a file in the server m/c ...im actually not transferring file from the server ,im just reading a file in the server m/c and then printing it in client m/c ...so is it possible to do it in tcp ??

karthik.c 6 Light Poster

i expect the file to be in client m/c and im sure that i've given the correct path for that file from the server m/c ...

karthik.c 6 Light Poster

hi guys i've problem in tcp:client/server program when i run it:
this program is to print the contents of a file in other m/c connected to LAN im sure that i've given the correct IPAdress,and also path of the file in other m/c but still its not printing the contents of the file.this is how i ran the client and server program:

tcpserver:
[root@localhost cworkspace]# gcc tcpserver.c
[root@localhost cworkspace]# ./a.out 192.168.1.19
The socket was created

workingBinding Socket
The Client 192.168.1.20 is Connected...
A request for filename /root/Desktop/scjp.txt Received..
File Open Failed: No such file or directory

tcpclient:
[root@localhost cworkspace]# gcc tcpclient.c
[root@localhost cworkspace]# ./a.out 192.168.1.20
The Socket was created
The connection was accepted with the server 192.168.1.20...
Enter The Filename to Request : /root/Desktop/scjp.txt
Request Accepted... Receiving File...

The contents of file are...


EOF
my code for server/client goes like this:

tcpserver:

#include<sys/types.h>

#include<sys/socket.h>

#include<netinet/in.h>

#include<sys/stat.h>

#include<unistd.h>

#include<stdlib.h>

#include<stdio.h>

#include<fcntl.h>



int main()

{

  int cont,create_socket,new_socket,addrlen,fd;

  int bufsize = 1024;

  char *buffer = malloc(bufsize);

  char fname[256];

  struct sockaddr_in address;



  if ((create_socket = socket(AF_INET,SOCK_STREAM,0)) > 0)

    printf("The socket was created\n");



  address.sin_family = AF_INET;

  address.sin_addr.s_addr = INADDR_ANY;

  address.sin_port = htons(10000);



  printf("\nworking");



  if (bind(create_socket,(struct sockaddr *)&address,sizeof(address)) == 0)

    printf("Binding Socket\n");

  listen(create_socket,3);

  addrlen = sizeof(struct sockaddr_in);

  new_socket = accept(create_socket,(struct sockaddr *)&address,&addrlen);



  if (new_socket > 0)

     printf("The Client %s is Connected...\n",inet_ntoa(address.sin_addr));

     recv(new_socket,fname, 255,0);

     printf("A request for filename …
karthik.c 6 Light Poster

hi jencas ,thanks for your suggestion and i've already google searched it and this was one of the simple as well as bad code i came across .so i would just like to know whether it forms a singleton class or not??

karthik.c 6 Light Poster

hi arkm,i would take your suggestion and improve myself and i'm really sorry for posting c++/c mixture code...exact code is like this...

#include<iostream.h>
class Sample
{
static int count;
public:
Sample()
{
if(count==1)
exit(0);
count++;
}
};
int Sample::count;
int main()
{
Sample s1;
Sample s2;
return(0);
}

i do know that it really is a bad code...but i would like to know whether it forms a singleton class or not??

karthik.c 6 Light Poster

Hi guys ,i came across coding in a book where they given the below program and named it as singleton class.but here we are able to create 2nd object and also call constructor for second object (only here do we check the status of count and exit from the program after creation of 2nd object).so what if i am right??n what if i can modify this program and make it create only one object??

#include<iostream.h>
class sample
{
    static int count;
    public:
        sample()
        {
            if(count==1)
                exit(0);
                printf("OBJ:%d\n",count);
            count++;
        }
};
int sample::count;
int main()
{
    sample s1;
    sample s2;
    return(0);
}
karthik.c 6 Light Poster

thanx comatose,your explanation was satisfactory and i understood what qw and my is ...

karthik.c 6 Light Poster

thanx comatose,my program is working now ,there was also error of not specifying scope in the client program and i would like to know:
-> what exactly 'qw' is and is it necessary to include it?
->significance of scope 'my' in a program

karthik.c 6 Light Poster

hi guys ,im new to perl programming and when i programmed tcp client-server coding in perl i encountered some problem saying :
Can't locate socket.pm in @INC (@INC contains: /usr/lib/perl5/5.8.5/i386-...)
i tried this in linux-centos and version of perl im using is: v5.8.5

my program was like this:
tcp-server:

#!/bin/perl -w
use strict;
use socket;qw(INADDR_ANY AF_INET SOCK_STREAM sockaddr_in);

my $proto=getprotobyname('tcp');
socket(SOMAXCONN,SOCK,AF_INET,SOCK_STREAM,$proto)or die "socket:$!";

my $port=getservbyname('daytime','tcp');
my $paddr=sockaddr_in($port,INADDR_ANY);

bind(SOCK,$paddr)or die "bind:$!";

listen(SOCK,SOMAXCONN)or die "listen:$!";

while(1)
{
	if(accept(CLIENT,SOCK))
	{
	    print CLIENT scalar localtime,"\n";
	    close CLIENT;
	}
}


tcp-client:

#!/bin/perl -w
use strict;
use socket; qw(AF_INET SOCKSTREAM inet_aton sockaddr_in);

$proto=getprotobyname('tcp');

socket(SOCK,AF_INET,SOCK_STREAM,$proto)or die "socket:$!";
$addr=inet_aton('localhost');
$port=getservbyname('daytime','tcp');

$paddr=sockaddr_in($port,$addr);

connect(SOCK,$paddr)or die "connect:$!";
print <SOCK>;

close(SOCK)||die "close:$!";

when i ran server program ,i encountered that error.any help appreciated....

karthik.c 6 Light Poster

thanx a lot vegaseat...

karthik.c 6 Light Poster

i want to print string(given as input) as number(o/p) and i did it in c using switch case .i want to do the same in python...
wat if python provides switch case??n do we have equivalent of it in python??

Examle:
input:three hundred and fifty(string)
output:350(number)

karthik.c 6 Light Poster

thanx ene and jrcagle...

karthik.c 6 Light Poster

hi guys i tried out wat u said but its showing error:name error
my code was like this:

first=input("Enter a sentence :\n")
second=""
vowels='aeiou'
for i in first:
if i in vowels:
second=second+i.upper()
else :
second=second+i
print second

i've one more doubt about assigning the value of vowel i.e
what is the difference between vowels='aeiou' and
vowels= and what will be the changes in coding if we initialize it in a list??

karthik.c 6 Light Poster

thanks scru and ene... :D

i think i've to go through basics well..and which book do u think is best and easy to learn for beginners in python??

karthik.c 6 Light Poster

hi scru,
it wud b more helpful if u can explain the above sol for this scenario
suppose if i give
>>> l1=[1,2,3,4,5]
>>> l1
[1, 2, 3, 4, 5]
i want l1 to print [1.0,2.0,3.0.....](in float)

karthik.c 6 Light Poster

Given a list of integers, generate the list of the corresponding floats.

karthik.c 6 Light Poster

hi guys
wat if List is equivalent 2 Arrays in c
or do we have Arrays seperately defined in python??