SEARCH YOUR SOLUTION HERE  

Teaching Myself C++ and getting stuck with a few syntax problems

Greetings,

I have been trying to teach myself C++ over the past few weeks and
have finally came across a problem I could not fix. I made a simple
program that prints out a square or rectangle using the * character.
The program was just for practice but I am having problems.

My main problem is, in my program I use 4 functions to change or
access two variables in my code. The variables are

itsHeight;
itsWidth;

The functions are
getHeight(), getWidth()
and
setHeight(), setWidth()

Now for some reason the value that gets stored in itsHeight and
itsWidth goes haywire and saves an astronomically huge number. It
makes my square huge to where you cant see it on a screen and takes a
long time to print. If I move the two variables outside of the class
and make them global, they work like normal. I know I must be doing
something wrong.

I am also having problems creating prototypes of my functions. I could
not create a prototype of my functions that needed to access my
Rectangle class. I was forced to define all the functions above the
Main and then define an object for each one. I was sure there was a
way to use prototypes so you could define your function later, but
somehow force the function to recognize my class ahead of time. Does
this make sense Right now only my menu function has a prototype. I
know defining a function before main is perfectly fine and that making
a prototype makes no difference but for the sake of learning, and the
sake of organization any help would rock!

The programs not done and there might be a few things in here that I
am not using at the very moment. That stuff should be commented out. I
also have not defined my variables very well between INT, Unsigneds,
longs and shorts. This is because I had it all nice and neatly
organized to what I think I would need for each function, but then
when I hit this brick wall I started changing them to INT to see if it
would make a difference. I will go back and make the appropriate
changes when I know what im doing wrong. Please lend advise to a newb!



#include
using namespace std;

//Define Variable types
typedef unsigned short int USI;
typedef unsigned long int ULI;
enum BOOL {FALSE, TRUE};
enum uchoose {print=1, area, perimeter, resize, salir};

//declare rectangle class
class Rectangle {
private: //Private Class Variables
int itsWidth;
int itsHeight;

public: //Public Variables and Functions
ULI printArea(){return itsHeight*itsWidth;}
ULI printPerimeter(){return itsHeight*2+itsWidth*2;}
int getHeight() const {return itsHeight;}
int getWidth() const {return itsWidth;}
int setHeight(int);
int setWidth(int);
};

int Rectangle::setHeight(int h) {
itsHeight=h;
}

int Rectangle::setWidth(int w) {
itsWidth=w;
}

void getMenu();

int printRect() {
Rectangle rect;
int h=rect.getHeight(),w=rect.getWidth();
for (USI x=0; x> w;
rect.setWidth(w);
}

void Area() {
Rectangle rect;
cout << rect.printArea();
}

void Perimeter() {
Rectangle rect;
cout << rect.printPerimeter();
}

int main() {
Rectangle rect;
USI choice;
BOOL x=FALSE;
while (!x) {
getMenu();
cin >> choice;
switch (choice)
{
case 1:
printRect();
break;
case 2:
Area();
break;
case 3:
Perimeter();
break;
case 4:
setSize();
break;
case 5:
x=TRUE;
break;
}
cout << endl;
}
}

void getMenu() {
cout << "Print the Rectangle\t(1)\n";
cout << "View the Area\t\t(2)\n";
cout << "View the Perimeter\t(3)\n";
cout << "Resize\t\t\t(4)\n";
cout << "Exit\t\t\t(5)\n";
}

,
> void setSize(Rectangle rect){
> int h,w;
> cout << "\nInput the Height: ";
> cin >> h;
> cout << "\nInput the Width: ";
> cin >> w;
> rect.setHeight(h);
> rect.setWidth(w);
> }
>
>
> I still am having problems with the output of hte square but a least I
> learned how to pass a referance of a class through the variables. When
> I get home I look closer to how I pass my values through the
> variables. I need to get more information on how making certain things
> a "const" benefits your program. Any how its all learning.
>
>

Posted On: Monday 5th of November 2012 01:08:00 AM Total Views:  287
View Complete with Replies




Related Messages:

atoi() and getting the current year   (145 Views)
I have two questions about the following code. Code: #include #include int isdate(char s[50]) { return 1; // fill in later } int main() { char s[50]; // storage for the date string int x; // loop counter x = 0; input: printf("Enter your birthday: YYYY/MM/DD"); // move the cursor back to the beginning of the date while (x < 10) { putchar('\b'); // print a backspace x++; } // check for a valid date if (!gets(s) || !isdate(s)) { printf("%s is not a valid date\n", s); goto input; // repeat the input steps } printf("You are %d years old\n", 2011 - atoi(s)); return 0; } My first question is about atoi(). This program does not work because atoi() looks at the entire date string instead of just the year. Is it possible to tell atoi() only to look at a certain number of characters My second question is about the current year. I've hard coded 2011, but calculating the current year would be better. How can that be done
program help cannot figure out why I am getting a freaking error   (275 Views)
Can anyone tell me why I am getting an error Code: // isbnreader123.cpp : main project file. #include "stdafx.h" //visual studio #include // printf scanf #include // tolower #include // strlen #include // isdigit atoi #include // system() void hello(void); //program to welcome user char is_valid (char vaild_y_n); // checks for yes or no to continue program int is_valid_isbn (char isbn[]); //function to check for non numeric input within ISBN int check_digit_calc(void); //calculates check digit char isbn[13]; //array for ISBN (character string) int isbn_num[13]; //array for ISBN (numeric) int main() { char y_n = 'y'; //sentinel int i, chk_valid, last_digit; // i=for counter, chk_vaild= switch, last dig= calculated last isbn digit hello(); //function call while(y_n =='y') { printf("\n\n Please enter you ISBN number"); scanf("%s",isbn); //reads isbn into character string isbm[] chk_valid = is_valid_isbn(isbn); //calls function to check for valid isbn if(chk_valid==1) { last_digit = check_digit_calc(); //recives calculated last digit if(isbn_num[9]==last_digit) printf(" \n\n The ISBN is valid\n\n"); else printf("\n\n You have entered an invalid ISBN \n\n"); } else printf("\n\n The ISBN you have entered contained non-numeric characters!\n\n"); printf("Do you wish to enter another ISBN number "); scanf("%c",&y_n); y_n=is_valid(y_n); //checks is user wants to continue system("cls"); } return 0; } void hello(void) //function to greet user { printf("\n *** Welcom to the ISBN check digit program where you enter and ISBN and we check it *****\n"); printf("\n ****How cool is that\a\..........**\n"); printf("\n **** Save your applause for after ****\n"); } char is_valid(char valid_y_n) { valid_y_n = tolower(valid_y_n); while(valid_y_n != 'y'&& valid_y_n != 'n') { printf("You can only enter 'y' or 'n'"); scanf("%c",&valid_y_n); valid_y_n = tolower(valid_y_n); } return (valid_y_n); int is_valid_isbn(char isbn[]) { int i, //counter loop j=0, //index for array invalid=1 ; char isbn_num1[1]; //singal digit string for atoi char *ptr_num1; // pointer for atoi ptr_num1 = &isbn_num1[0]; //initialization of pointer for atoi for (i = 0; i
trouble in getting this crc coding right   (225 Views)
hi i am stuck with doing crc coding for c programming i ask for user to define the divisor and dataword and got the augemented dataword but have trouble in divinding the augemented dataword with the divisor and getting the remainder result.i am stuck with the algo there here's my coding Code: #include #include #include int main() { int a[20],b[20],c[20],i,k,j,n,s=0,t=0; printf ( "Welcome to the CRC Encoder/Decoder!\n"); printf ( "press n to exit at anytimes\n"); /* do{*/ printf("enter size of dataword\n"); scanf("%d",&n); printf("enter dataword to be transfer bit by bit\n"); for (i=0;i
Problem with getting largest number read from a file?   (184 Views)
. I have a program that I have to write that reads 20 ints in from a file and then lists the greatest and smallest ones. For right now I'm just trying to make it run to get the largest number, and then I'll work on the smallest. The program compiled, but when I ran it it gave me some really LARGE number, and I'm not sure why. I used a past model we did to find the largest of a list of test grades in an array, and tried to apply it here, but I'm thinking that may not be the best way to go about this This is what I have: Code: # include int main() { char filename[50]; int numbers[20]; printf ("Please enter the file that you wish to open: "); scanf("%s", filename); FILE *infile=fopen(filename, "r"); if(infile==NULL) { printf( "The file was not successfully opened"); } fscanf(infile, "%d", numbers); int m = numbers[0]; int i; for(i=0; i < sizeof(numbers)/(*numbers); i++) { if(numbers[i]>m) {m = numbers[i];} } printf("The largest number is %d", m); fclose(infile); return 0; } Thank you for any help!
need a little help getting started   (180 Views)
nevermine
Using libpcap, getting different results if compared to TCPDUMP   (179 Views)
I am using pcap library to sniff traffic. I am a newbie to network programming but still I managed to get a demo code working. Here is the function which is doing the actual logic : Code: /* callback function that is passed to pcap_loop(..) and called each time a packet is recieved */ void callback(u_char *useless,const struct pcap_pkthdr* pkthdr,const u_char* packet) { struct ether_header *ethheader; struct iphdr *ipheader; struct tcphdr *tcpheader; struct in_addr source, dest; //Points to ethernet header ** Will this header be constant for any type of connection ethheader = (struct ether_header *)packet; //Points to IP header ** But how do we know IP is being used ipheader = (struct iphdr *)(packet + sizeof(struct ether_header)); //Points to TCP header ** But how do we know that TCP is being used could be UDP too... tcpheader = (struct tcphdr *)(packet + sizeof(struct ether_header) + sizeof(struct iphdr)); //Points to the TCP Payload const char *payload = (u_char *)(packet + sizeof(struct ether_header) + sizeof(struct iphdr) + sizeof(struct tcphdr)); source.s_addr = ipheader->saddr; dest.s_addr = ipheader->daddr; printf("From: %s:%i\n", inet_ntoa(source), ntohs(tcpheader->source)); printf("To: %s:%i\n", inet_ntoa(dest), ntohs(tcpheader->dest)); printf("Seq num: %u\n", ntohl(tcpheader->seq)); printf("length Transport payload: %lu\n", pkthdr->len - (sizeof(struct ether_header) + sizeof(struct iphdr) + sizeof(struct tcphdr))); printf("length of this packet (off wire): %d\n\n\n", pkthdr->len); } The problem here is, when I start both my program and TCPDUMP and open a website suppose 'google.com', then the IP addresses that are spit out by my program and that by TCPDUMP are different. For example the first few packets that I get from my TCPDUMP are : Code: tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on ppp0, link-type LINUX_SLL (Linux cooked), capture size 96 bytes 07:48:38.116354 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [P.], seq 694114432:694115363, ack 3682572338, win 63, options [nop,nop,TS val 521038 ecr 1670476261], length 931 07:48:38.116948 IP 115.241.128.67.47356 > 202.138.97.193.domain: 60501+ PTR 51.236.125.74.in-addr.arpa. (44) 07:48:38.769817 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [P.], seq 0:931, ack 1, win 63, options [nop,nop,TS val 521104 ecr 1670476261], length 931 07:48:38.839851 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [.], ack 931, win 210, options [nop,nop,TS val 1670554629 ecr 521038], length 0 07:48:38.867778 IP 202.138.97.193.domain > 115.241.128.67.47356: 60501 NXDomain 0/1/0 (104) 07:48:38.909909 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [.], seq 1:1419, ack 931, win 210, options [nop,nop,TS val 1670554700 ecr 521038], length 1418 07:48:38.909936 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [.], ack 1419, win 85, options [nop,nop,TS val 521118 ecr 1670554700], length 0 07:48:38.909954 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [.], seq 1419:2837, ack 931, win 210, options [nop,nop,TS val 1670554700 ecr 521038], length 1418 07:48:38.909960 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [.], ack 2837, win 108, options [nop,nop,TS val 521118 ecr 1670554700], length 0 07:48:38.909970 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [P.], seq 2837:3685, ack 931, win 210, options [nop,nop,TS val 1670554700 ecr 521038], length 848 07:48:38.909979 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [.], ack 3685, win 130, options [nop,nop,TS val 521118 ecr 1670554700], length 0 07:48:38.909987 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [.], seq 3685:5103, ack 931, win 210, options [nop,nop,TS val 1670554700 ecr 521038], length 1418 07:48:38.909992 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [.], ack 5103, win 153, options [nop,nop,TS val 521118 ecr 1670554700], length 0 07:48:38.919885 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [.], seq 5103:6521, ack 931, win 210, options [nop,nop,TS val 1670554700 ecr 521038], length 1418 07:48:38.919910 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [.], ack 6521, win 176, options [nop,nop,TS val 521119 ecr 1670554700], length 0 07:48:38.919933 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [P.], seq 6521:7781, ack 931, win 210, options [nop,nop,TS val 1670554700 ecr 521038], length 1260 07:48:38.919939 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [.], ack 7781, win 198, options [nop,nop,TS val 521119 ecr 1670554700], length 0 07:48:39.089842 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [.], ack 931, win 210, options [nop,nop,TS val 1670554889 ecr 521104,nop,nop,sack 1 {0:931}], length 0 07:48:39.129870 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [.], seq 7781:9199, ack 931, win 210, options [nop,nop,TS val 1670554943 ecr 521118], length 1418 07:48:39.129891 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [.], ack 9199, win 220, options [nop,nop,TS val 521140 ecr 1670554943], length 0 07:48:39.129907 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [.], seq 9199:10617, ack 931, win 210, options [nop,nop,TS val 1670554943 ecr 521118], length 1418 07:48:39.129913 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [.], ack 10617, win 243, options [nop,nop,TS val 521140 ecr 1670554943], length 0 07:48:39.149886 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [.], seq 10617:12035, ack 931, win 210, options [nop,nop,TS val 1670554943 ecr 521118], length 1418 07:48:39.149910 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [.], ack 12035, win 266, options [nop,nop,TS val 521142 ecr 1670554943], length 0 07:48:39.149927 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [.], seq 12035:13453, ack 931, win 210, options [nop,nop,TS val 1670554943 ecr 521118], length 1418 07:48:39.149934 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [.], ack 13453, win 288, options [nop,nop,TS val 521142 ecr 1670554943], length 0 07:48:39.159877 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [.], seq 13453:14871, ack 931, win 210, options [nop,nop,TS val 1670554949 ecr 521118], length 1418 07:48:39.159901 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [.], ack 14871, win 311, options [nop,nop,TS val 521143 ecr 1670554949], length 0 07:48:39.159918 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [P.], seq 14871:16249, ack 931, win 210, options [nop,nop,TS val 1670554949 ecr 521118], length 1378 07:48:39.159924 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [.], ack 16249, win 333, options [nop,nop,TS val 521143 ecr 1670554949], length 0 07:48:39.259776 IP 115.241.128.67.59324 > 202.138.97.193.domain: 65226+ AAAA google.com. (28) 07:48:39.369845 IP 202.138.97.193.domain > 115.241.128.67.59324: 65226 0/1/0 (78) 07:48:39.369955 IP 115.241.128.67.39995 > 202.138.97.193.domain: 44179+ AAAA google.com. (28) 07:48:39.430093 IP 115.241.128.67.32813 > 74.125.236.51.www: Flags [P.], seq 687814410:687815506, ack 3653235322, win 501, options [nop,nop,TS val 521170 ecr 1670476295], length 1096 07:48:39.482234 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [P.], seq 931:2221, ack 16249, win 333, options [nop,nop,TS val 521175 ecr 1670554949], length 1290 07:48:39.489840 IP 202.138.97.193.domain > 115.241.128.67.39995: 44179 0/1/0 (78) 07:48:39.489962 IP 115.241.128.67.37470 > 202.138.97.193.domain: 12909+ A google.com. (28) 07:48:39.759821 IP 74.125.236.51.www > 115.241.128.67.32813: Flags [.], ack 1096, win 267, options [nop,nop,TS val 1670555536 ecr 521170], length 0 07:48:39.789817 IP 202.138.97.193.domain > 115.241.128.67.37470: 12909 5/4/4 A 74.125.236.49,[|domain] 07:48:39.789827 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [.], ack 2221, win 250, options [nop,nop,TS val 1670555618 ecr 521175], length 0 07:48:39.790047 IP 115.241.128.67.40701 > 74.125.236.49.www: Flags [S], seq 2929756677, win 5840, options [mss 1460,sackOK,TS val 521206 ecr 0,nop,wscale 7], length 0 07:48:39.849815 IP 74.125.236.51.www > 115.241.128.67.32814: Flags [P.], seq 16249:16464, ack 2221, win 250, options [nop,nop,TS val 1670555704 ecr 521175], length 215 07:48:39.849825 IP 115.241.128.67.32814 > 74.125.236.51.www: Flags [.], ack 16464, win 356, options [nop,nop,TS val 521212 ecr 1670555704], length 0 07:48:39.859828 IP 74.125.236.51.www > 115.241.128.67.32813: Flags [P.], seq 1:147, ack 1096, win 267, options [nop,nop,TS val 1670555722 ecr 521170], length 146 07:48:39.859848 IP 115.241.128.67.32813 > 74.125.236.51.www: Flags [.], ack 147, win 501, options [nop,nop,TS val 521213 ecr 1670555722], length 0 07:48:39.949835 IP 74.125.236.49.www > 115.241.128.67.40701: Flags [S.], seq 1590680668, ack 2929756678, win 5672, options [mss 1430,sackOK,TS val 1670555824 ecr 521206,nop,wscale 6], length 0 07:48:39.949867 IP 115.241.128.67.40701 > 74.125.236.49.www: Flags [.], ack 1, win 46, options [nop,nop,TS val 521222 ecr 1670555824], length 0 07:48:39.949973 IP 115.241.128.67.40701 > 74.125.236.49.www: Flags [P.], seq 1:69, ack 1, win 46, options [nop,nop,TS val 521222 ecr 1670555824], length 68 07:48:40.089836 IP 74.125.236.49.www > 115.241.128.67.40701: Flags [.], ack 69, win 89, options [nop,nop,TS val 1670555983 ecr 521222], length 0 07:48:40.119826 IP 74.125.236.49.www > 115.241.128.67.40701: Flags [P.], seq 1:512, ack 69, win 89, options [nop,nop,TS val 1670556024 ecr 521222], length 511 07:48:40.119864 IP 115.241.128.67.40701 > 74.125.236.49.www: Flags [.], ack 512, win 54, options [nop,nop,TS val 521239 ecr 1670556024], length 0 07:48:40.129833 IP 74.125.236.49.www > 115.241.128.67.40701: Flags [F.], seq 512, ack 69, win 89, options [nop,nop,TS val 1670556024 ecr 521222], length 0 07:48:40.129968 IP 115.241.128.67.40701 > 74.125.236.49.www: Flags [F.], seq 69, ack 513, win 54, options [nop,nop,TS val 521240 ecr 1670556024], length 0 07:48:40.130387 IP 115.241.128.67.55976 > 202.138.97.193.domain: 22249+ AAAA Google. (32) 07:48:40.269828 IP 74.125.236.49.www > 115.241.128.67.40701: Flags [.], ack 70, win 89, options [nop,nop,TS val 1670556163 ecr 521240], length 0 07:48:40.289835 IP 202.138.97.193.domain > 115.241.128.67.55976: 22249 1/1/0 CNAME[|domain] 07:48:40.289946 IP 115.241.128.67.46537 > 202.138.97.193.domain: 15996+ A Google. (32) 07:48:40.399838 IP 202.138.97.193.domain > 115.241.128.67.46537: 15996 6/4/4 CNAME[|domain] 07:48:40.400078 IP 115.241.128.67.41252 > 74.125.236.50.www: Flags [S], seq 2926797497, win 5840, options [mss 1460,sackOK,TS val 521267 ecr 0,nop,wscale 7], length 0 While from my program I get: Code: From: 24.63.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 945 length of this packet (off wire): 999 From: 38.214.115.241:25025 To: 128.67.202.138:47356 Seq num: 3473460 length Transport payload: 34 length of this packet (off wire): 88 From: 24.62.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 945 length of this packet (off wire): 999 From: 230.57.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 14 length of this packet (off wire): 68 From: 162.163.202.138:32835 To: 97.193.115.241:53 Seq num: 3103522928 length Transport payload: 94 length of this packet (off wire): 148 From: 224.174.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 1432 length of this packet (off wire): 1486 From: 27.224.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 14 length of this packet (off wire): 68 From: 224.173.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 1432 length of this packet (off wire): 1486 From: 27.223.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 14 length of this packet (off wire): 68 From: 226.230.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 862 length of this packet (off wire): 916 From: 27.222.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 14 length of this packet (off wire): 68 From: 224.171.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 1432 length of this packet (off wire): 1486 From: 27.221.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 14 length of this packet (off wire): 68 From: 224.170.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 1432 length of this packet (off wire): 1486 From: 27.220.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 14 length of this packet (off wire): 68 From: 225.71.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 1274 length of this packet (off wire): 1328 From: 27.219.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 14 length of this packet (off wire): 68 From: 230.38.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 26 length of this packet (off wire): 80 From: 224.167.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 1432 length of this packet (off wire): 1486 From: 27.218.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 14 length of this packet (off wire): 68 From: 224.166.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 1432 length of this packet (off wire): 1486 From: 27.217.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 14 length of this packet (off wire): 68 From: 224.165.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 1432 length of this packet (off wire): 1486 From: 27.216.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 14 length of this packet (off wire): 68 From: 224.164.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 1432 length of this packet (off wire): 1486 From: 27.215.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 14 length of this packet (off wire): 68 From: 224.163.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 1432 length of this packet (off wire): 1486 From: 27.214.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 14 length of this packet (off wire): 68 From: 224.202.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 1392 length of this packet (off wire): 1446 From: 27.213.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 14 length of this packet (off wire): 68 From: 38.115.115.241:25025 To: 128.67.202.138:59324 Seq num: 3473444 length Transport payload: 18 length of this packet (off wire): 72 From: 162.188.202.138:32835 To: 97.193.115.241:53 Seq num: 3887857750 length Transport payload: 68 length of this packet (off wire): 122 From: 38.104.115.241:25025 To: 128.67.202.138:39995 Seq num: 3473444 length Transport payload: 18 length of this packet (off wire): 72 From: 113.106.115.241:60467 To: 128.67.74.125:32813 Seq num: 5253375 length Transport payload: 1110 length of this packet (off wire): 1164 From: 22.202.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 1304 length of this packet (off wire): 1358 From: 162.187.202.138:32835 To: 97.193.115.241:53 Seq num: 2621112406 length Transport payload: 68 length of this packet (off wire): 122 From: 38.92.115.241:25025 To: 128.67.202.138:37470 Seq num: 3473444 length Transport payload: 18 length of this packet (off wire): 72 From: 230.43.74.125:32835 To: 236.51.115.241:80 Seq num: 2150488511 length Transport payload: 14 length of this packet (off wire): 68 From: 162.20.202.138:32835 To: 97.193.115.241:53 Seq num: 2455634172 length Transport payload: 234 length of this packet (off wire): 288 From: 230.42.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 14 length of this packet (off wire): 68 From: 149.229.115.241:60465 To: 128.67.74.125:40701 Seq num: 5287584 length Transport payload: 22 length of this packet (off wire): 76 From: 229.82.74.125:32835 To: 236.51.115.241:80 Seq num: 2150554495 length Transport payload: 229 length of this packet (off wire): 283 From: 27.211.115.241:60467 To: 128.67.74.125:32814 Seq num: 5253471 length Transport payload: 14 length of this packet (off wire): 68 From: 229.150.74.125:32835 To: 236.51.115.241:80 Seq num: 2150488511 length Transport payload: 160 length of this packet (off wire): 214 From: 117.177.115.241:60467 To: 128.67.74.125:32813 Seq num: 5253375 length Transport payload: 14 length of this packet (off wire): 68 From: 230.33.74.125:32835 To: 236.49.115.241:80 Seq num: 2667405007 length Transport payload: 22 length of this packet (off wire): 76 From: 149.236.115.241:60465 To: 128.67.74.125:40701 Seq num: 5287584 length Transport payload: 14 length of this packet (off wire): 68 From: 149.167.115.241:60465 To: 128.67.74.125:40701 Seq num: 5287584 length Transport payload: 82 length of this packet (off wire): 136 From: 230.40.74.125:32835 To: 236.49.115.241:80 Seq num: 2667405007 length Transport payload: 14 length of this packet (off wire): 68 From: 228.40.74.125:32835 To: 236.49.115.241:80 Seq num: 2667405007 length Transport payload: 525 length of this packet (off wire): 579 From: 149.234.115.241:60465 To: 128.67.74.125:40701 Seq num: 5287584 length Transport payload: 14 length of this packet (off wire): 68 From: 230.38.74.125:32835 To: 236.49.115.241:80 Seq num: 2667405007 length Transport payload: 14 length of this packet (off wire): 68 From: 149.233.115.241:60465 To: 128.67.74.125:40701 Seq num: 5287584 length Transport payload: 14 length of this packet (off wire): 68 From: 38.24.115.241:25025 To: 128.67.202.138:55976 Seq num: 3473448 length Transport payload: 22 length of this packet (off wire): 76 From: 230.37.74.125:32835 To: 236.49.115.241:80 Seq num: 2667405007 length Transport payload: 14 length of this packet (off wire): 68 From: 162.161.202.138:32835 To: 97.193.115.241:53 Seq num: 3668443246 length Transport payload: 92 length of this packet (off wire): 146 From: 38.8.115.241:25025 To: 128.67.202.138:46537 Seq num: 3473448 length Transport payload: 22 length of this packet (off wire): 76 From: 161.250.202.138:32835 To: 97.193.115.241:53 Seq num: 3049849108 length Transport payload: 258 length of this packet (off wire): 312 From: 121.77.115.241:60466 To: 128.67.74.125:41252 Seq num: 5287539 length Transport payload: 22 length of this packet (off wire): 76 From: 63.186.74.125:32835 To: 236.50.115.241:80 Seq num: 2703531801 length Transport payload: 22 length of this packet (off wire): 76 From: 121.84.115.241:60466 To: 128.67.74.125:41252 Seq num: 5287539 length Transport payload: 14 length of this packet (off wire): 68 From: 121.11.115.241:60466 To: 128.67.74.125:41252 Seq num: 5287539 length Transport payload: 86 length of this packet (off wire): 140 From: 63.193.74.125:32835 To: 236.50.115.241:80 Seq num: 2703531801 length Transport payload: 14 length of this packet (off wire): 68 From: 61.100.74.125:32835 To: 236.50.115.241:80 Seq num: 2703531801 length Transport payload: 618 length of this packet (off wire): 672 From: 63.191.74.125:32835 To: 236.50.115.241:80 Seq num: 2703531801 length Transport payload: 14 length of this packet (off wire): 68 From: 121.82.115.241:60466 To: 128.67.74.125:41252 Seq num: 5287539 length Transport payload: 14 length of this packet (off wire): 68 From: 121.81.115.241:60466 To: 128.67.74.125:41252 Seq num: 5287539 length Transport payload: 14 length of this packet (off wire): 68 From: 37.210.115.241:25025 To: 128.67.202.138:50585 Seq num: 3473450 length Transport payload: 24 length of this packet (off wire): 78 From: 162.129.202.138:32835 To: 97.193.115.241:53 Seq num: 3315138700 length Transport payload: 122 length of this packet (off wire): 176 From: 63.190.74.125:32835 To: 236.50.115.241:80 Seq num: 2703531801 length Transport payload: 14 length of this packet (off wire): 68 Done processing packets... wheew! I dont see the IP address matching.....where am I at fault
I am getting "segment fault" for simple program. Can help any one   (277 Views)
HI , I am trying to execute below simple program. But i am getting "Segmentation fault" after selecting choice 1. Please hlep me regarding this. Code: #include #include struct node { int data; struct node *addr; }; struct node *first; int main() { int choice; printf("%d \n",first); while(1) { printf("enter the choice\n"); printf (" 1.display\n 3.quit\n"); scanf("%d",&choice); switch (choice) { case 1: display(); break; case 3: quit(); } } return 0; } int display() { struct node *temp; temp=(struct node *)malloc(1 * sizeof(struct node)); printf("entered into display function\n"); if (temp == NULL) { printf("Memory is not allocated to create new node\n"); return 0; } printf ("%d\n",temp); printf ("%d\n",temp); printf ("%d\n",first->data); if ( first->addr == NULL) { printf ("List is empty\n"); return 0; } else { temp=first; printf ("The elements in Linked list are\n"); while (temp->addr !=NULL) { printf ("%d\n",temp->data); temp = temp->addr; } } return 0; } int quit() { printf("entered into exit\n"); exit (0); } o/p: enter the choice 1.display 3.quit 1 entered into display function 145903624 145903624 Segmentation fault
getting started with lambda function in boost   (181 Views)
Searching for very good but simple explanation of lambda functions in c ++ using boost lambda library . Just started reading boost documentation .Any other good documents,article,url is highly appreciated
getting unique identifier out of two variables   (162 Views)
given a set of pairs P = {(x1,y1), (x2,y2), ... (xn,yn)} where each pair is unique, is there a way to get Q = {z1, z2, ..., zn} that is to map each pair of values to another unique one Is hashing the only way to achieve this
How to restrict 'some' code from getting compiled/built? (without #define)   (219 Views)
I need to build two executables from my code, one having all the code (and thus application features) and other not having it all. How to best manage the code that shouldn't go in one of the executables My first thought is to use conditional compilation with #define and #ifdef etc but its getting messy, are there better ways to manage this The problem in detail: #. There is a class A with virtual foo1 and foo2 #. There are 'lots' of derived classes of A which implement foo1 and foo2 #. Executable1 needs to use both foo1 and foo2 #. Executable2 only needs to use foo1, never needs foo2 How to make sure that all the foo2 code never gets into executable2 Lots of #ifdefs can be used for this but is there a better solution Maybe some clever use of templates Something else less complicated
Local Variables not getting values back   (171 Views)
Hi , I am facing a strange problem.. I am calling a function func2 from func1. Before calling func2 all the local variables in func1 looks fine and has their respective values. When function returns back from func2 to func1 all the local variables in func1 has values 0xfdfdfd. Can somebody please explain me what is happening and what is the solution for this
getting Error :: explicitly instantiate functional Template   (193 Views)
Hi , i writing a shared library ,containing code in template i trying to explicitly instantiate functional & class template ........But i am getting Error #include #include "commonfile.h" template const T & min(const T & a , const T & b) {return (a < b a : b );} template const T & max(const T & a , const T & b) {return (a < b b : a );} template int max(int,int); template int min(int,int); > g++ -g commonfile.h commonfile.cc g++: compilation of header file requested commonfile.cc:16: template-id `max' for `int max(int, int)' does not match any template declaration commonfile.cc:17: template-id `min' for `int min(int, int)' does not match any template declaration , Pallav singh wrote: > On Sep 15, 1:16 pm, Ian Collins wrote: >> Pallav singh wrote: >>> Hi , >>> i writing a shared library ,containing code in template >>> i trying to explicitly instantiate functional & class >>> template ........But i am getting Error >>> #include >>> #include "commonfile.h" >>> template >>> const T & min(const T & a , const T & b) >>> {return (a < b a : b );} >>> template >>> const T & max(const T & a , const T & b) >>> {return (a < b b : a );} >>> template int max(int,int); >> template int max(int,int); >> > Hi Ian > > After using following way of expilicit Instantiation ....compilation > Error goes > But i donot find Symbol w.r.t. function's in my Object File... > > Currently i am using gcc version 3.2.3 > > template int max(int,int); > template int min(int,int); > These aren't specialisations. The specialisations would be declared as template const int& max( const int&, const int&); template const int& min( const int&, const int&); and will have to be defined somewhere in your application. -- Ian Collins.
Code getting Crashed( C++)   (211 Views)
On Aug 7, 11:00 pm, Erik Wikstrm wrote: > On 2008-08-07 11:39, Pallav singh wrote: > > std::auto_ptr CreateNew_PizzaProduct() > > { pizza.reset(new Pizza()); } > > Actually I'm surprised your code crashes, because it should not even > compile. In the above function you forgot to return a value. The above code need not generate a compiler diagnostic. Furthermore, no code 'should not compile' unless it contains a #error directive. The behaviour is undefined if the function is actually called.
getting current timestamp   (175 Views)
I want to find the current time stamp in micro sec precision. The requirement is, my function is executed in an infinite loop. I measure a value and check if the value computed is what i expected 9forget all this stuff). I want to print the time stamp every time that event occurs. So my requirement is printing the current timestamps. so I can calculate the average time (in micro secs) after which such an event occur... I hope I made my requirement clear. Can anybody pls help me with this problem. I searched many discussion but couldn't find satisfactory answer.
virtual function in inherited class not getting called   (172 Views)
I have a base class CEventSelect a bit like this: class CEventSelect { virtual void OnConnected(); } and a network interface class a bit like this: class networkinterface : public CEventSelect { virtual void OnConnected(); } The base CEventSelect class calls it's OnConnected() function when a client receives notification from the network that it is connected. But I wanted my networkinterface::OnConnected() method to be called But it wasn't. I understand polymorphic functions and I think I understand why it is not working the way I wanted. Because CEventSelect calls its own OnConnected() method does mean that the inheriting OnConnected() will be called. But this is the behaviour I want. The actual connection is notified by the base class - but I want my interface class to someone get notified of the connection. How can I get the networkinterface class to be notified about the connection
getting access to enclosing class   (164 Views)
hi, I would like to write some code where a C++ class (let's call it Containee) which is a member variable of a Container class can call methods in its Container class without holding a direct pointer to the Container class: #include class Containee { public: Containee (int offset); void Do (void); private: int m_offset; }; class Container { public: Container (); void Do (void); Containee m_containee; private: static int GetOffset (void); }; Container::Container () : m_containee (GetOffset ()) {} int Container::GetOffset (void) { Container *self = 0; Containee Container::* ptr = &Container::m_containee; long containee = (long) &(self->*ptr); return containee; } void Container:o (void) { std::cout Do (); } }; However, I have not yet been able to figure out how to calculate the offset and feed it to this Containee class template. I tried the following: #include class Base {}; template class Containee : public Base { public: void Do (void); }; class Container { public: void Do (void); Containee m_containee; private: }; void Container:o (void) { std::cout Do (); } int main (int argc, char *argv[]) { Container container; container.m_containee.Do (); return 0; } But that just does not work with my version of g++ (4.1.3): test.cc:19: error: incomplete type =E2=80=98Container=E2=80=99 used in ne= sted name specifier test.cc:19: error: template argument 3 is invalid test.cc: In function =E2=80=98int main(int, char**)=E2=80=99: test.cc:46: error: request for member =E2=80=98Do=E2=80=99 in =E2=80=98container.Container::m_containee=E2=80=99, which is of non-class= type =E2=80=98int=E2=80=99 Which somewhat does not surprise me very much: g++ wants to know the type= of Container. To do this, it needs the type of m_containee which itself needs the type of Container... And, I really dislike the syntax I had to use for the Containee instance declaration. So, would anyone have an idea on how I could hack this together I know that what I am doing here is especially evil but, I can't refrain myself from doing it: it does make me feel a little bit warm inside. Mathieu -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
String referenced by one object is getting changed when accessed by some other object.......   (195 Views)
Hi , I am facing a very Wierd problem. Below is the sample code snippet to understand the problem: #include #include using namespace std; class B { public: string str; }; class A { public: void Details (B *objInfo); }; void A :: Details (B* objInfo) { cout
Re: getting a name of a polymorphic type   (166 Views)
Hi Martin,
vc6 exception not getting caught in vs2k5   (255 Views)
My application has a small JNI piece written in C++. This piece was developed using VC++ 2k5. We statically link with some .lib's which were built using vc6. I see that exceptions thrown by some api's in these .lib's are not getting caught but are causing the app to crash. When this code was "ported" to vc6 this wasn't observed. It so happens we also support HPUX n Solaris n it works fine there too. Why's this happening
'Password protected screen saver' is not getting activated!!   (379 Views)
I have an simple MFC dialog based application. On launch of that application 'Password protected screen saver' is not getting activated after the screen saver timeout. If 'On resume, password protect' option unchecked, I am getting the Screen saver. Application not generating any of the keyboard or any user events to disturb the system. If I exit the application every thing works normal(Means password protected screen saver gets activates after screen saver time out period.) Please help me in understanding, why 'Password protected screen saver' is not getting activated.