Hi,

I recently wrote a small morse code converter and then decided to combine it with the network programming stuff I'm learning and then decided to mash that up in turn with some OO programming which I am also learning and it would all run in linux. Not that I'm trying to overload myself or anything :P Anyways, I wrote a class, which is shown below, along with a few member functions which facilitate my server/client communication and stuck it all in a header file. Problem is the compiler always complains that it can't find the header file. I tried putting the header file in the compiler's search path, changing the suffix from '.h' to '.hpp' (which it should have been in the first place right?) and tried enclosing it in quotes i.e (#include<"morse.hpp">) alas nothing works. So I checked google but the various tutorials I read didn't mention anything I could see as protentially causing my problem. As far as I can tell I am doing everything right, but this is the first time I am using header files, and OOP so I guess I can blame that :P.

It probably doesn't help that I am trying to compile this on linux live cds and on NetBSD running on a sparc64 processor lol but it should work right?

Anyway here are the errors and code:

-bash-2.05b$ g++ morse_serv.cpp -o morse.serv
morse_serv.cpp:4:22: "morse.hpp": No such file or directory
morse_serv.cpp: In function `int main(int, char**)':
morse_serv.cpp:27: error: `morse' undeclared (first use this function)
morse_serv.cpp:27: error: (Each undeclared identifier is reported only once for each function it appears in.)
morse_serv.cpp:27: error: parse error before `;' token
morse_serv.cpp:30: error: invalid conversion from `char*' to `short unsigned int'
morse_serv.cpp:48: error: invalid conversion from `long unsigned int' to `__socklen_t*'
morse_serv.cpp:54: error: conversion from `__in_addr_t' to non-scalar type `in_addr' requested
morse_serv.cpp:75: error: `m' undeclared (first use this function)
morse_serv.cpp:75: error: parse error before `]' token
Now I'm concentrating on the class and header file releated errors as I am pretty sure I have had the others before and they are fairly easy to fix. Btw, this is the output from g++ on netbsd^^.

Code:
#include<iostream>
#include<cstdlib>

class morse
{
	public:
		char lookup[28] = { 'a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' ,'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o' ,'p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' ,'x' ,'y' ,'z' ,'.' ,',' };		
		char morse[28][6] = {{ '.','-'},			//a                  The code tags seem to 
			        		{ '-','.','.','.'},		//b                         be screwing with my 
			        		{ '-','.','-','.'},		//c                         indentation....sorry
			        		{ '-','.','.'},			//d                        guys!
						{ '.'},					//e
						{ '.','.','-','.'},		//f
						{ '-','-','.'},			//g
						{ '.','.','.','.'},		//h
						{ '.','.'},				//i
						{ '.','-','-','-'},		//j
						{ '-','.','-'},			//k
						{ '.','-','.','.'},		//l
						{ '-','-'},				//m
						{ '-','.'},				//n
						{ '-','-','-'},			//o
						{ '.','-','-','.'},		//p
						{ '-','-','.','-'},		//q
						{ '.','-','.'},			//r
						{ '.','.','.'},			//s
						{ '-'},					//t
						{ '.','.','-'},			//u
						{ '.','.','.','-'},		//v
						{ '.','-','-'},			//w
						{ '-','.','.','-'},		//x
						{ '-','.','-','-'},		//y
						{ '-','-','.','.'},		//z
						{ '.','-','.','-','.','-'},		//.
						{ '-','-','.','.','-','-'}		//,
						};
		void ctob( char input[] )
		{//open func
			int input_len = strlen(input);
			if ( input[0] == '\0' )
			{
				cout<<"No input given, exiting...";
				exit(1);
			}
			for ( int i = 0; i < input_len; i++ )
			{
				for ( int j = 0; j < 28; j++ )
				{
					if ( input[i] == lookup[j] )
					{
						cout<< morse[j] <<"\n";
						int k = 0;
						while ( morse[j] [k] != '\0' )
						{
							if ( morse [j] [k] == '.' )
							{
								system("beep -f 700 -l 100");
								system("sleep 0.17 s");
							}
							else if ( morse [j] [k] == '-' )
							{
								system("beep -f 700 -l 100");
								system("sleep 0.17 s");
							}
							k++;
						}
						system("sleep 0.17 s");
						break;
					}
				}
			}
		}//close func
		void mtob(char input[])
		{//open func
			int l = 0;
			while ( input[l] != '\0' )
			{
				if ( input[l] == '.' )
				{
					system("beep -f 700 -l 100");
					system("sleep 0.17 s");
				}
				else if ( input[l] == '-' )
				{
					system("beep -f 700 -l 100");
					system("sleep 0.17 s");
				}
				l++;
				cout<< input[i];
			}
			system("sleep 0.17 s");
		}//close func
		char ctom(char input[])
		{//open func
			int ctom_len = strlen(input);
			for ( int i = 0; i < ctom_len; i++ )
			{
				for ( int j = 0; j < 28; j++ )
				{
					if ( input[i] == lookup[j] )
					{
						char morse_code[] = morse[j];
					}
				}
			}
		}//close func
};//close class
I have included those header files as the compiler complained otherwise.

Code:
#include<iostream>
#include<sys/types.h>
#include<sys/socket.h>
#include<"morse.hpp">
#include<netinet/in.h>
#include<arpa/inet.h>

#define CLIENT_QUEUE_SIZE 2
#define MAX_DATA 1024

using namespace std;

int main(int argc, char *argv[])
{
	if ( argc == 3 )
	{
		cout<<"USAGE: ./morse_list [PORT NUMBER]\n";
		exit(-1);
	}
	int sock, cli_sock;
	char *greeting = "Connected to the server.\n";
	char input[MAX_DATA];
	int len = strlen(greeting);
	int recv_len;
	struct sockaddr_in serv;
	struct sockaddr_in client;
	morse m;

	serv.sin_family = AF_INET;
	serv.sin_port = htons(argv[1]);
	serv.sin_addr.s_addr = INADDR_ANY;
	memset(serv.sin_zero, '\0', sizeof(serv.sin_zero));
	if ((sock = socket( PF_INET, SOCK_STREAM, 0 )) == -1 )
	{
		cout<<"Could not open socket.\n";
		exit(-1);
	}
	if ((bind( sock, ( struct sockaddr *)&serv, sizeof(serv))) == -1 )
	{
		cout<<"Could not bind socket.\n";
		exit(-1);
	}
	if ((listen( sock, CLIENT_QUEUE_SIZE )) == -1 )
	{
		cout<<"Could not listenon the network.\n";
		exit(-1);
	}
	cli_sock = accept( sock, (struct sockaddr *)&client, sizeof(client));
	if ( cli_sock == -1 )
	{
		cout<<"Could not accept connection.\n";
		exit(-1);
	}
	cout<<"Connection on port "<<ntohs(client.sin_port)<<"from "<<inet_ntoa(client.sin_addr.s_addr)<<"\n";	
	int bytes_sent = send( cli_sock, greeting, len, 0 );
	if ( bytes_sent == -1 )
	{
		cout<<"FAIL: Could not send greeting\n";
	}
	while(1)
	{
		memset(input, '\0', MAX_DATA);
		if ( (recv( cli_sock, input, MAX_DATA, 0 )) == -1 )
		{
			cout<<"Failed to receive data.\n";
			exit(-1);
		}
		recv_len=strlen(input);
		if ( input[0] == '\0' )
		{
			cout<<"Empty packet received, waiting for next useful packet...";
		}
		else
		{
			m.mtob(input[]);
		}
	}
	close(cli_sock);
	cout<<"Client connection terminated.\n";
	close(sock);
}
Thanks in advance,

Calef13