programmersbook 17 Junior Poster

You welcome

programmersbook 17 Junior Poster

You have to initilialize the FOO in constructor, FOO is a reference and has to initialize in contructor

class baz
{
  private:
  int foo;

  public:
  const int & FOO;
  baz() : FOO(foo) {} // constructor
 ~baz(){ } // destructor

};
programmersbook 17 Junior Poster

Hi,

line 19 prototype, return type is char, line 172 implementation no return type.

Changed it to return type char and everybody will be happy :)

programmersbook 17 Junior Poster

hmm, it compiles without problems with gcc.

How do you compile it?

programmersbook 17 Junior Poster

Line 39 you should type cast:

median = (element[(int)(nep/2)] + element[(int)(nep/2-1)]) / 2;
programmersbook 17 Junior Poster

Some things got messed up it should be like this:

main.cpp

//file1.cpp
#include<iostream>
#include"file3.h"

using std::cout;
using std::cin;

namespace baz
{
    extern MyClass foobar;
}

int main()
{
    baz::foobar.setFOO();
    
    baz::foobar.bar();
    cout << *baz::foobar.FOO << "\n";
    
    cin.ignore();
    
    return 0;
}
//file3.h

namespace baz{

class MyClass
{
      private:
      int foo;
      
      public:      
      void bar(void);
      void setFOO(void);
      int * FOO;
};

}
//file2.c

#include"file3.h"

namespace baz
{
    MyClass foobar;

    void MyClass::bar(void)
    {
         foo = 42;
    }

    void MyClass::setFOO(void)
    {
         FOO = &foo;     
    }

}
programmersbook 17 Junior Poster

Hi,

which compilation error do you get?

programmersbook 17 Junior Poster

HI,

first of all, it's not a good idea to store the mail plain, better generate a crypt key, and same the email on your side with the key.

Anyway it would be like this:

<form method="post" action="formposting.php">
<input type="text" name= "title" size="22">
<input type="text" name= "email" size="22">
<?php 

if(!$_COOKIE['cookname']) {

 echo "<input type=\"checkbox\" name=\"remember\" id=\"remember\" value="<?php if($_COOKIE[$cookname]) print $_COOKIE[$cookname];  ?>"/> Remember me on this computer"; 
} 

else{
echo $email; 
echo "Forget Me{delete cookie//help here too}";
} 
?>
</div>
<input type="submit" value="post"/>
</form>


if (isset($_POST['remember'])) {
	parse_str($_COOKIE[$cookname]);
	$number_of_days = 100000 ;
	$date_of_expiry = time() + 60 * 60 * 24 * $number_of_days ;
	setcookie( "cookname", $_POST['remember'], $date_of_expiry, "/", "url.com" );  
}
programmersbook 17 Junior Poster

Line 24.25. is kind of the same?

I you pop you need to release memory and check if you are and the end or will will get an segv. And if you are in C++ a class would just cool.

programmersbook 17 Junior Poster

line 6: should be:

void merge(char[],int, char[], int,char[],int*);

better:

void merge(char[],int, char[], int,char[],int&);
//----------merging-----------
void merge (char array1[],int size1, char array2[],int size2, char c[],int &size )
{
     for (int k=0;k< size1;k++)
     {
         c [k] =array1[k];
         }
         for (int k=0;k<size2;k++)
         {
             c [size1+k] = array2[k];
             
             size=size1+size2;
             }
             
}

Did you look at c++ algorithm like merge?

programmersbook 17 Junior Poster

Hi!

Can you be more specific?

programmersbook 17 Junior Poster

Hi!

ftp.sendcmd is only for FTP commands. Google gave me this: http://commandline.org.uk/python/sftp-python-really-simple-ssh/

programmersbook 17 Junior Poster

how about:

struct movieData
{
	std::string title;
	std::string director;
	int year;
	int time;
};
programmersbook 17 Junior Poster

Hi,

first of all storing a BLOB is very bad design.

But, it would be like this:

blob_value = open('image.jpg', 'rb').read()
sql = 'INSERT INTO Tab1(blob_field) VALUES(%s)'
args = (blob_value, )

cursor.execute (sql, args)
connection.commit()
programmersbook 17 Junior Poster

did you try:

fourMatrix::fourMatrix(fourVector a, fourVector b, fourVector c, fourVector d): i(a),j(b),k(c),l(d){
      }

else the compiler takes "i" as local variable

or use:

class fourMatrix{
public:
	fourVector m_i,m_j,m_k,m_l;

...
}

then you see is a class attribute

fourMatrix::fourMatrix(fourVector i, fourVector j, fourVector k, fourVector l): m_i(i), m_j(j), m_k(k), m_l(l){
      }
programmersbook 17 Junior Poster

did you try:

fstream file;
 file.open("Tbl_cliente.txt", ios::in); // open a file for input
 file.unsetf(ios::skipws);

getline(file, Cli_nombre, '#');
getline(file, Cli_apellido, '#');
getline(file, Cli_dirr, '#');
getline(file, Cli_total_compras, '#');
getline(file, Cli_balance, '#');
programmersbook 17 Junior Poster

i see, well when i will do it like this:

void check_name()
{   name *strt;
    strt = start_ptr;
    cout << endl;
          
          for (name * strt = start_ptr;strt->nxt !=NULL;strt=strt->nxt)
          {      
          
            if (enter_name == strt->boy_name )
            {
                cout << enter_name << " is ranked #" << strt->rank;
                cout << " in popularity among boys.\n" << endl;
                break;
            }
            else if (enter_name == strt->girl_name) 
            {
                 cout << enter_name << " is ranked #" << strt->rank;
                cout << " in popularity among boys.\n" << endl;
                 break;
                              
            }
          }
    cout << enter_name << " is not ranked among the";
      cout << " top 1000 names." << endl;
}

call check_name() after add_names();

Full code:

#include <iostream>
#include <cstdlib>
#include <fstream>

using namespace std;

struct name
       { int rank;
         string boy_name;
         string girl_name;
         name *nxt;
         };
         
name *start_ptr = NULL;
name *current;

void add_names();
void check_name();

string enter_name;

int main()
{
    start_ptr = new name;
    cout << "Please enter a first name to see its ranking" << endl;
    cout << "among the top 1000 baby names." << endl;
    cin >> enter_name;
    cout << endl;
    add_names();
    check_name();
    
    system("PAUSE");
    return 0;
}

    

void add_names()
{   //name *temp, *temp2;
    //temp = new name;
    name * prior = new name;// * temp;
    int ranking;
    //int i=0;
    string male_name, female_name;
    ifstream in_stream("babynames2004.txt");
    
    //in_stream.open; //opens and loads names & ranks from file
    if (in_stream.fail())
   {
    cout << "File failed to open." << endl;
    cout << "Program will now close." << endl;
    system("PAUSE");
    exit(0);
   }
    
    in_stream >> ranking>> male_name >> …
mcap61 commented: Saved my a$$. Thanks for your help, I wish i could return the favor. +1
programmersbook 17 Junior Poster

i would do it like this: http://clipboard.it/v/z2b/ no pointers, better to understand.

programmersbook 17 Junior Poster

Hi!

Sorry the http://www.cs.nccu.edu/~gmilledge/co...ynames2004.txt doesnt work.

I think you should use std::list, and no pointers if it's not neccessary! It will make your wile easier ;)

programmersbook 17 Junior Poster
strcpy(can->name, ch );

better use std::string.

programmersbook 17 Junior Poster

gcc doesn't complain, hmm.

it's looks like Splint has a problem.

did you try:

int r = scanf("%f%f", &height, &weight);

float bmi = (float)weight/(height*height);
programmersbook 17 Junior Poster

he doesn't like:

vector<int[3]> resolutions;

should be:

vector<int> resolutions;

if you need an array:

vector<list<int>> resolutions;
kirennian commented: Problem solved, thanks. +1
programmersbook 17 Junior Poster

did you try:

typedef struct DISPLAY_DEVICE_CAPABILITIES{
	vector<int[3]> resolutions;
	int brightness;
}DISPLAY_DEVICE_CAPABILITIES;
programmersbook 17 Junior Poster

You should type cast it:

float bmi =(float) (weight/(height*height));
programmersbook 17 Junior Poster
kvprajapati commented: Cool link! +6
programmersbook 17 Junior Poster

You welcome!

if you have it like this:

void *ptr;

and give it to send, send will complain, because behind ptr is no memory allocated!

programmersbook 17 Junior 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);
programmersbook 17 Junior Poster

The keys are unique, if the key is already present he will be updated.

Use multimap to insert each time a new value.

programmersbook 17 Junior Poster

how are the permissions set?

is -Index active? How the cfg looks like?

programmersbook 17 Junior Poster

the better question is, why it crashes? What is the real reason?

programmersbook 17 Junior Poster

why not like this:

#include <iostream>
#include <string>

class A{
 std::string s;
 public:
  A(){ s = "1234567"; }
  char operator []( const int index ){ return s.at(index); }
};

int main (int argc, char const* argv[])
{
    A a;
    std::cout << a[0] << std::endl;
    return 0;
}
programmersbook 17 Junior Poster

I'm sorry

iter->first.first;
      iter->first.second;
programmersbook 17 Junior Poster

you need to type cast it:

const int** constPtr2=(const int**)ptr2;
programmersbook 17 Junior Poster

here you go:

iter->first->first; 
iter->first->second;
programmersbook 17 Junior Poster

better have the send only once:

when it's almost DRY ;)

//read file and send
	if (myfile.is_open()) //if the file is open
	{	
		ss << "HTTP/1.0 200 OK \r\n\r\n";
		while (getline(myfile, line))
		{			
			ss << line;
			ss << "\n";
		}
	} 
    else{
		ss << "HTTP/1.0 404 FILE NOT FOUND \r\n\r\n";
	}
	
	nbytes=send(newsockfd, ss.str().c_str(), ss.str().size(), 0);
	
	if(nbytes < 0) {
	    perror("send error");	
	    exit(1);
	}
programmersbook 17 Junior Poster

Correct me if I'm wrong, but shouldn't you first accept incoming connection and this connection put into epoll? Epoll will tell when the socket is ready to read or write.

As far as i see, epoll_wait is to early...

After bind you should accept.

programmersbook 17 Junior Poster

Does the function "setFirstName" take the parameter as reference?

programmersbook 17 Junior Poster

and to make it more smooth

instread of:

strcat(strfinal, "HTTP/1.0 200 OK \r\n\r\n");
	if (myfile.is_open()) //if the file is open
	{
		while (! myfile.eof() ) //while the end of file is NOT reached
		{
			getline (myfile,line);
			cout << line << endl;
			strcat(strfinal, line);
		}
	}  
       send(newsockfd, strfinal, sizeof(strfinal), 0);

better:

#include <stringstream>
std::sstream ss; 

    ss << "HTTP/1.0 200 OK \r\n\r\n";
    
	if (myfile.is_open()) //if the file is open
	{
		while (getline (myfile,line) ) //while the end of file is NOT reached
		{
			cout << line << endl;
			ss << line;
		}
	}  
    
    send(newsockfd, ss.str().s_str(), ss.str().size(), 0);
programmersbook 17 Junior Poster

line 36:
should to be: std::string line;

line 80:
strcat(strfinal, line.c_str() );

instread of:

while (! myfile.eof() ) //while the end of file is NOT reached
		{
			getline (myfile,line);
			cout << line << endl;
			strcat(strfinal, line);
		}

better:

while (getline (myfile,line)) //while the end of file is NOT reached
		{
			cout << line << endl;
			strcat(strfinal, line);
		}
programmersbook 17 Junior Poster

Hi!

I not sure that i got it, can you provide a example? I love examples!

programmersbook 17 Junior Poster

Hi!

I would create a base class, from which the myTemplateClass will inherit.

like this:

class TemplateClassBase{};

template<class C>class myTemplateClass : TemplateClassBase{};

This should be a list:

myTemplateClass * templateClassPtrArray[10];

This is better:

std::list<TemplateClassBase*> templateClassPtrArray;
templateClassPtrArray.push_back( new myTemplateClass<int>() );
templateClassPtrArray.push_back( new myTemplateClass<char>() );

Code is NOT tested, was written from scratch.

When you have no problem to save anything.

I hope i was clear :/

programmersbook 17 Junior Poster

tried this?

ifstream Data
programmersbook 17 Junior Poster

It's the same.

programmersbook 17 Junior Poster

An even easier way :Link

yeah, but we dont want to count like \r\n ., etc..

programmersbook 17 Junior Poster

I would put the whole parameter in a struct, when is more readable:

vector<double>& A, vector<double>& B, vector<double>& C, double x, double& p, double& px, double& pxx, int& degree

better:

struct SomeName{
vector<double> A;
vector<double> B;
vector<double> C;
double x;
double p; 
double px;
double pxx; 
int degree;
}
programmersbook 17 Junior Poster

the whole thing is confusing me.

programmersbook 17 Junior Poster
class A:
    _a = 33

class B:
    __b = 22
    

a = A()
b = B()

print a._a
print b.__b

Output:

33
Traceback (most recent call last):
  File "p.py", line 12, in <module>
    print b.__b
AttributeError: B instance has no attribute '__b'
programmersbook 17 Junior Poster

You welcome!

programmersbook 17 Junior Poster

Well, maybe you should redesign your program? It looks odd.

programmersbook 17 Junior Poster

did you try without "endl"?