jaepi 22 Practically a Master Poster

Hello there, I've encountered a syntax in one of the examples I'm studying.

*pStatus = *pStatus | DC_ST_DISK_IN | DC_ST_TRAYCLOSE | DC_ST_WRITING;  //<--notice the "|"

Is this a form of piping? Like in bash script in Linux which supports piping in there commands? uhmmm.. What does it imply, or what is its purpose? Thanks

jaepi 22 Practically a Master Poster

Thanks guys. :)

jaepi 22 Practically a Master Poster

How about googling around. There are websites (maybe) that could give you such awful problems for you to practice. *chuckles*

jaepi 22 Practically a Master Poster

Its just another way of initializing variables -- those could have just as easily been coded like this:

CDriveControl::CDriveControl()
{
     m_pPort = NULL;
     m_pSPTIDriver = NULL;
     m_bInitFlag = NULL;
     m_onlycomp = NULL;
}

Oh, I see. Is there an advantage of using the one that I've mentioned to the one that you stated? Is there any critical difference? Thank you for putting out my worries.

jaepi 22 Practically a Master Poster

Hello there. I have here a constructor of class CDriveControl and class CSPTIDriver..

class CSPTIDriver;
class CDriveControl{
   public:
      CDriveControl();
      CDriveControl(const char* pPort);
       ......
       ......
 
   protected:
      char* m_pPort;
      CSPTIDriver* m_pSPTIDriver;
      bool m_bInitFlag;
      bool m_onlycomp;
}

It was defined outside the class.

CDriveControl::CDriveControl(void)
:m_pPort(NULL)                        //Object drive
,m_pSPTIDriver(NULL)                //SPTI object
,m_bInitFlag(false)                    //Formatted flag
,m_onlycomp(false)
{
}

CDriveControl::CDriveControl(const char* pPort)
:m_pPort(NULL)                        //Object drive
,m_pSPTIDriver(NULL)                //SPTI object
,m_bInitFlag(false)                    //Formatted flag
,m_onlycomp(false)
{    
    if(pPort == NULL){
        Trace(false, "CDriveControl();pPort==NULL\n");
        return;
    }
    //Port name is kept
    m_pPort = new char[strlen(pPort)+1];
    strcpy(m_pPort, pPort);
//    ::InitializeCriticalSection(&m_cCrtSection);
    
}

My question is, what is the reason that these protected variables where placed here?

CDriveControl::CDriveControl(void)
:m_pPort(NULL)                    //<---here    
,m_pSPTIDriver(NULL)          //<---also here      
,m_bInitFlag(false)               //<---guess what?    
,m_onlycomp(false)             //<---you got it right again!
{ //<---what's up with this?
} //<---and this one too?

I searched some function tutorials but I was not able to find any explanation with this one. I'm currently studying classes and I was able to find this example code of constructor. Could anyone explain to me what is the use of doing that? I'm a having a hard time realizing what in the world is it's purpose. Thank you very much...

jaepi 22 Practically a Master Poster

Hello there, I just want to ask if any of you guys here had experienced writing hardware controllers (dvd-rom, hard disk) using scsi protocol-multimedia commands. I just want to know your suggestions or maybe tutorials or example codes to well experienced in mmc (both windows and linux :)) that would help me to further investigate. Thank you.

jaepi 22 Practically a Master Poster

im sorry, mods, kindly delete the duplicate... :)

jaepi 22 Practically a Master Poster

Welcome to Daniweb, see you around ^^

we both have the same blood from Rizal, Bonifacio, blah blah blah...lol

jaepi 22 Practically a Master Poster

Welcome to Daniweb, see you around ^^

we both have the same blood from Rizal, Bonifacio, blah blah blah...lol

jaepi 22 Practically a Master Poster
jaepi 22 Practically a Master Poster

Could he be using interpreter software that caused an unfortunate linguistic misunderstanding? I've seen that happen on other boards...

If he did, could it be an excuse? *chuckles*

jaepi 22 Practically a Master Poster

As what I have read, after forking, the main program was split into 2, thus creating the child process as the copy of the parent, that's why "su" performed twice. <- Am I correct with that? Thank you very much for that detailed explanation. :)

jaepi 22 Practically a Master Poster

a) learn some netiquette

I certainly agree with that.

jaepi 22 Practically a Master Poster

You can check this out. This answers your question on how to write graphics program.

http://www.gtk.org/tutorial/index.html

If you mean of graphics as an interface.

hurry up

What's up with that?

jaepi 22 Practically a Master Poster

Warm *HUG* for granny Beverly. Welcome to the community.

jaepi 22 Practically a Master Poster

In addition, I have here a test program. I used fork and exec to execute the command in Linux "switch user" or the "su" command. I was surprised to see two outputs. It executed two "su" commands. Does this mean that forking a child will create a copy of a process when exec is used??

Here's my test program.

#include <iostream>
#include <unistd.h>

using namespace std;

int main(){
   const char* command = "su";
   pid_t child_p;
   
   child_p = fork();
 
   execvp(command, NULL);
   return 0;
}
jaepi 22 Practically a Master Poster

Hello there. Is there someone kind enough to please explain to me the difference of using fork() and exec() with system() in invoking a process. I just want to know their difference according to well experienced with processes here. And what is the most efficient in invoking a process between the two. Thanks.

jaepi 22 Practically a Master Poster

hehe, why am i reinventing the wheel?? *chuckles*

jaepi 22 Practically a Master Poster

hello guys, thanks for that warm, comfy and mushy welcome...*evil grin*

jaepi 22 Practically a Master Poster

Have assigned a value to the string but when I assign values to the whole lo (DEF112 and XYZ113) it does'nt go out of the loop.
With the above mentioned method where ABC111 is given a value x,
then my output display x instead of ABC111 - on the cout statement

oh, you mean the ABC111 blah blah are the module thingies, i thought they were variables...

jaepi 22 Practically a Master Poster

your ABC111, DEF112, XYZ113 has no value...it will just continue to execute the do{} since the the while is giving off false boolean value...try giving it a value...
try this 1 and study the result...

void inputAndValidate(string &moduleCode,int &numberHours)
{
string ABC111 = "x";
do
{
cout << " Enter module code: ";
cin >> moduleCode;
}

while (moduleCode!=ABC111);
cout << " Enter number of hours: ";
cin >> numberHours;

}

enter "x" or any other value then study the result..

jaepi 22 Practically a Master Poster

5. Programmers are always under pressure form the managers and management and often feel being neglected and underpaid and overused. If this is the case, what could be the solutions?

as a trainee, i get a fair salary...and im just learning and learning, hassle free...:)

jaepi 22 Practically a Master Poster

...but i was not able to introduce myself...im jaepi and i love to eat, sleep and repeat...*bow*...lol

jaepi 22 Practically a Master Poster

yeah, fake accounts and spammers are now dominating the space of tom...tsk tsk...almost 75% of my messages, bulletins and comments came from spams...

jaepi 22 Practically a Master Poster

is this your assignment?

jaepi 22 Practically a Master Poster

thank you dude, i'll read this one...i might have some questions, is it ok to ask? i might need your help... :)

jaepi 22 Practically a Master Poster

I've been reading a lot since Monday (mostly socket programming in Linux) and all I get is creating basic socket servers (like echoing, hello world and stuff). My task is to create a web server and all I can see are socket server tutorials? Am I gone or something? Could someone here,please please please, explain to me what to do in making/creating/programming a web server in Linux. HELP!

jaepi 22 Practically a Master Poster

oh...i see...thanks dude...what i made was not a web server but a socket server...uhmmm...could i create a web server out of this socket server?

jaepi 22 Practically a Master Poster

that's my suspicion too...oh well, i'll just create a server...whatever server that is. lol

jaepi 22 Practically a Master Poster

readable font size and not so *eye blinding* font colors...a motif...well organized body of text...no typo errors, you don't want to end up reading this -> "I kill beers" or "I drink bears"...and oh, no viruses attached...

jaepi 22 Practically a Master Poster

so, you write/create/program the host, not the server? so what i did is not a server, but a host that sends hello world string to it's requesting client?

what's the difference between a host and a server?

jaepi 22 Practically a Master Poster

what about this

float fahrenheit =(celsius*(9.0/5.0))+32;

no need to type cast

jaepi 22 Practically a Master Poster

i don't know if this will work...just try this one...
you have a string from the command line, you store that string into a variable then convert it using atoi() function

string command_line_arg ="1234"

int x;

x = atoi(command_line_arg);

don't forget to include the header <stdlib.h>

works well for me...just try....

jaepi 22 Practically a Master Poster

hello there, i just want to ask...how would i apply threading to a web server app?? my problem is, i dunno how to create a web server...i created a simple server that sends hello world to a client that sends a request...how would i apply threading to this one??

jaepi 22 Practically a Master Poster

Hello there, I'm currently practicing network programming under Unix system. I have here a sample code from the tutorial. I compiled it, it has no errors. But when I execute it, it prompts me this "connect: Connection refused". What do you think is the problem. Here's my code:

#include <netinet/in.h>
#include <sys/socket.h>
#include <netdb.h>
#include <sys/types.h>
#include <iostream>
#define PORT 13
#define BUFLEN 1024

using namespace std;

struct sockaddr_in s_add;
int suck_it, bind_me, r_con;
char* p_buff;
char buf[BUFLEN+1];
struct hostent* h_name;
int main(int argc, char *argv[]){
        if(argc < 2){
                cout << "Missing hostname" << endl;
                exit(1);
        }

        h_name = gethostbyname(argv[1]);

        if(!h_name){
                cout << "couldn't resolve host name" << endl;
        }

        memset(&s_add, 0, sizeof(s_add));

        s_add.sin_family = AF_INET;
        s_add.sin_port = htons(PORT);

        memcpy(&s_add.sin_addr.s_addr, h_name->h_addr_list[0], h_name->h_length);

        suck_it = socket(AF_INET, SOCK_STREAM, 0);


        if(suck_it<=-1){
                perror("im your worst nightmare");
        }

        r_con = connect(suck_it, (struct sockaddr*) &s_add, sizeof(s_add));

        if(r_con){
                perror("connect");
        }

        p_buff = buf;

        r_con = read(suck_it, p_buff, BUFLEN-(p_buff-buf));

        while(r_con){
                p_buff += r_con;
        }

        close(suck_it);

        *p_buff = ' ';
        cout << "Time: " << buf;

        return 0;
}

Help please.

jaepi 22 Practically a Master Poster

Hello there, I'm currently working on to some interface using gtk. I'm using PuTTY, doing programming remotely, cause I was told not to use the Linux server unit for surfing, so I'm using the windows unit for internet surfing and at the same time programming by the use of PuTTY. My problem is, I cannot load the GUI (of course in Linux) when I run it in the windows computer, but when I execute my program in the Linux computer, it runs well. It prompts a warning when I execute my application in Windows.

[dinglej@localhost gtk_practice]$ g++ my_cpp_ver.cpp -o my `pkg-config --cflags --libs gtk+-2.0`
[dinglej@localhost gtk_practice]$ ./my

(my:3974): Gtk-WARNING **: cannot open display:

I'm just wondering because when I execute console based programs it runs pretty well, but when I load a GUI using my Windows unit, it does not function. Can anyone here, who is kind enough, to please explain to me why?
By the way, I'm using iMax to change my view between Windows and Linux. Thank you.

jaepi 22 Practically a Master Poster

Thank you ~s.o.s~, I was able to produce my very first GUI in Linux using gtk+ 2.0.

jaepi 22 Practically a Master Poster

Hello there! can anybody here point me to any GUI programming in Linux tutorials. Been googling around but no good hits. Thanks.

jaepi 22 Practically a Master Poster

Dude, the article is creepy. LOL

jaepi 22 Practically a Master Poster

hahaha, i was testing the void pointer, that's why im dying to get it right...hahaha...

are void pointers useless?? haha...

im just asking... why use void pointers as parameters anyway, if you can just use the type itself?

*chuckles*

jaepi 22 Practically a Master Poster

Haha...I have to speed up my study. An undeniable fact that 1 month of learning such powerful language is not enough. But I have no choice. I have a project this June, and that is to create a dvd-rw driver controller. I was assigned to this team handling c++ and linux, that's why I have to cope up with them.

jaepi 22 Practically a Master Poster

haha, i forgot to place the reference operator & to the arguments passed. this solved my confusion. lol.

jaepi 22 Practically a Master Poster

I changed all the void to it's corresponding type. And I've added dynamic memory allocation to my pointer. Problem solved. But what if I did not changed the voids to it's corresponding data type? What do you think is the problem with the void thing?

jaepi 22 Practically a Master Poster

This is my solution. I used a pointer of type Student(w/c is my structure). The problem is, I'm getting an error. There is something wrong with my code, *chuckles*, that I can't figure out.

here's the code:

#include <iostream>
#include <pthread.h>
#include <string>
#include <stdlib.h>
#define NUM_OF_STUDENTS 2
#define NUM_OF_INFO 4

using namespace std;

struct Student{
        string first_name, last_name, course;
        int id_no;

};

void print_student(void* f_name, void* l_name, void* course_, void* id_no_ );

Student student1;
Student student2;
Student* pStudent;
string info[] = {"First Name: ", "Last Name: ", "Course: ", "ID #: "};
string container[NUM_OF_INFO];
const char* temp;
int q,j;

int main(){
        for(j = 0; j<NUM_OF_INFO; j++){
                cout << info[j];
                cin >> container[j];
        }
        j = 0;
        pStudent->first_name = container[j];
        pStudent->last_name = container[j+1];
        pStudent->course = container[j+2];
        temp = container[j+3].c_str();
        q = atoi(temp);
        pStudent->id_no = q;

        print_student(pStudent->first_name, pStudent->last_name, pStudent->course, pStudent->id_no);
        return 0;
}

void print_student(void* f_name, void* l_name, void* course_, void* id_no_ ){

        for(int i = 0; i<NUM_OF_STUDENTS; i++){
                cout << "STUDENT #" << i+1 << endl;
                cout << "First Name: " << *((string*) f_name) << endl;
                cout << "Last Name: " << *((string*) l_name) << endl;
                cout << "Course: " << *((string*) course_) << endl;
                cout << "ID #: " << *((int*) id_no_) << endl;
                cout << "\n";
        }

}

and this is the error:

my_first_thread.cpp: In function `int main()':
my_first_thread.cpp:39: error: cannot convert `std::string' to `void*' for argument `1' to `void print_student(void*, void*, void*, void*)'

In addition,uhmm, how do I create a post of "code" that …

jaepi 22 Practically a Master Poster

I was not able to view your reply before I posted the rep point thing. Oh well, that's fine with me, you have given me an idea. I could still use it. Maybe I'm just too kind to give rep points to those who are very helpful here, specially the mods.

jaepi 22 Practically a Master Poster

Oh, I've already given you a rep point somewhere in my threads here, in this forum. I'm going to implement threading by this example. Uhmmm, maybe you could criticize my work after i finished, to see if I really did understand what I've read. If that's ok with you? hehehe...

jaepi 22 Practically a Master Poster

Thanks! I'll try it. I have thought of using an array but I was too afraid to try because I have suspicions of producing an error, but I was wrong. I have come up with another solution, using temp variable of type string. I'll try it first. Thank you again man. You earn a rep point for your kindness.

jaepi 22 Practically a Master Poster

Hello there, I'm practicing structures and accessing data in a structures. I have here a program that gets an input of string and int from a user. I placed it inside a loop where every time the loop refreshes, it changes the information it gets. My problem is, how do i changed the input variable inside a loop?

here is my code, it is unfinished:

#include <iostream>
#include <pthread.h>
#include <string>
#define NUM_OF_STUDENTS 2
#define NUM_OF_INFO 4
using namespace std;

struct Student{
        string first_name, last_name, course;
        int id_no;

};

void print_student(void* f_name, void* l_name, void* course_, void* id_no_ );

Student student1;
Student student2;
string info[] = {"First Name: ", "Last Name: ", "Course: ", "ID #: "};

int main(){
       
        for(int j = 0; j<NUM_OF_INFO; j++){
                cout << info[j];
                cin >> student1.first_name;
        }


        return 0;
}

void print_student(void* f_name, void* l_name, void* course_, void* id_no_ ){

        for(int i = 0; i<NUM_OF_STUDENTS; i++){
                cout << "STUDENT #" << i+1 << endl;
                cout << "First Name: " << *((string*) f_name) << endl;
                cout << "Last Name: " << *((string*) l_name) << endl;
                cout << "Course: " << *((string*) course_) << endl;
                cout << "ID #: " << *((int*) id_no_) << endl;
                cout << "\n";
        }

}

Notice the for loop inside the main?

string info[] = {"First Name: ", "Last Name: ", "Course: ", "ID #: "};
for(int j = 0; j<NUM_OF_INFO; j++){
                cout << info[j];
                cin >> student1.first_name;
}

How do I change the input variable every time the …

jaepi 22 Practically a Master Poster

Thank you.

jaepi 22 Practically a Master Poster

Self study and lots of self study. Experiential types of learning is the best. We both have similarities and I'm investing my time reading and asking help to experts here to things that I'm not sure of. And oh, I agree wtih mariocatch.