lAmoebal 1 Junior Poster in Training

Doing your previous example, I would still need to go through each index in the array, wouldn't I? Unless I'm just misunderstanding. What I ultimately want to do is take 4 bytes and put them in 0-3, 4 more bytes and put them in 4-7, then 8-11, then 12-15. Is the only way to do this byte by byte with memcpy or setting up a for loop?

lAmoebal 1 Junior Poster in Training

Thanks Ancient Dragon,
That seemed to get rid of my runtime errors, but it still doesn't seem to be filling the array with the correct values. Could you take a look at how I'm doing it and tell me how it could be corrected?

int numtype = htons(5);
char type[sizeof(int)];
memcpy(type, (char *)&numtype, sizeof(int));
message[0] = *type;

int numseq = htons(sequence);
har seq[sizeof(int)];
memcpy(seq, (char *)&numseq, sizeof(int));
message[4] = *seq;

int nump1 = htons(0);
char p1[sizeof(int)];
memcpy(p1, (char *)&nump1, sizeof(int));
message[8] = *p1;

int nump2 = htons(0);
char p2[sizeof(int)];
memcpy(p2, (char *)&nump2, sizeof(int));
message[12] = *p2;

I should note the message is declared as char message[16] elsewhere in the program, and sequence is just a 4 digit number.

lAmoebal 1 Junior Poster in Training

Is there a way to copy a whole smaller array into a section of a larger array? For example, if I have an array of 4 characters, and an array of 16, can I copy the 4 characters into the first 4 of the array of 16. Then another 4 characters to 4-7, etc. I know it's possible to do with a loop, but I was wondering if there was a way to do it otherwise. Here's the section of code that I'm trying to get to work.

int numtype = htons(5);
char type[4] = "";
_itoa_s(numtype, type, 4, 10);
message[0] = *type;

I need to convert the message to be sent byte by byte to a server with each 4 bytes containing control messages for the server. This is just one of the 4 of 16 bytes of the whole message.

lAmoebal 1 Junior Poster in Training

I'm not sure I completely understand your question. Are you trying to add just the odd numbers up until a certain value? If that's the case, in your while loop change

sum=sum+(2*counter-1);

to

if (counter%2 != 0)
{
  sum = sum + counter;
}

If you need to output each number at the same time, before your loop, put

cout << "sum = ";

And make the if statement I just posted look like..

if (counter%2 != 0)
{
  sum = sum + counter;
  if (counter != n)
  {
     cout << counter << " + ";
  }
  
  else
  {
     cout << counter << " = ";
  }
}

And then after your loop, simply output the sum variable.

lAmoebal 1 Junior Poster in Training

You need to use cin.getline in order to include the spaces. Here's a tutorial on it.

http://www.cplusplus.com/reference/iostream/istream/getline.html


strlen is also a Cstring function, so instead of string, you would need to include string.h. Then after setting L = strlen(Fname), in your cout statement, you can just cout L, rather than L.length();.

lAmoebal 1 Junior Poster in Training

Hey guys, I have a problem. When I try to run a program that I've compiled with VS 2005 on a different machine that does not have VS, I get this error.

"The application failed to initialize properly (0x0150002). Click on OK to terminate the application."

I've installed the Microsoft Visual C++ 2005 SP1 Redistributable Package on the target machine and have the one dll required to run my program in the program folder but I still get the error.

Any ideas?

lAmoebal 1 Junior Poster in Training
lAmoebal 1 Junior Poster in Training

There's no guarantee that it will return anything because your return statements are both inside of if statements. Since you're returning true and false you could also make the function a bool rather than int.

lAmoebal 1 Junior Poster in Training

Don't resurrect old threads!

Inevitably, if you use the search feature you'll stumble upon an interesting thread that you think you can add to. Resist the temptation to post until you've looked at the post date for the most recent post in that thread. It's possible that the thread is years old and you have no business bumping it to the top of the list. A thread is considered old after two months.

Let dead threads lie, don't post in them!

http://www.daniweb.com/forums/thread78223.html

lAmoebal 1 Junior Poster in Training

I think you meant this, rather than what you had.

divisor=pow ((rate+1),(numberofpayments));

If this doesn't fix it, let me know. I only looked at that line, and not at the rest of your code.

lAmoebal 1 Junior Poster in Training

try to put this function instead of the last one printcheck.
may be the reply is too late but it could be useful for others.
best regards

Only about a year late..

lAmoebal 1 Junior Poster in Training

A void function receives values just like any other function, it just doesn't return any.

lAmoebal 1 Junior Poster in Training

I can't imagine a Game Developers course for intro to C++ would be any different than any other intro to C++ course. There's plenty of online tutorials out there...like the ones mosta posted, but if you're looking for a class on it, I'd say only take that class if it's not any more expensive than any other intro to C++ course.

lAmoebal 1 Junior Poster in Training

From just glancing over your code quickly I noticed you're missing a default for your switch. It doesn't seem like that would cause the error you're getting, but you should still fix it.

Can you copy the error exactly please?


Also - You never read in choice, so it's always going to be set to 1 since you set it on line 40.

X is also never initialized to anything.

lAmoebal 1 Junior Poster in Training

I see what you mean about the modules now. What I had downloaded before was Net SNMP but not the module for perl so I now am running that and am starting to get general grasp on the code. I reworked it a little but I have one question.

#!perl -w
use strict;
use Net::SNMP;
use POSIX qw(strftime);


my $now = localtime time;
my $filename = (strftime "%Y%m%d", localtime(time)) . ".txt";     #yyyymmdd.txt 
open  LOG, ">>/SNMP Script Logs/$filename";                       #C:/SNMP Script Logs/Date.txt
print LOG "----------------------------------\n";
print LOG "$now\n----------------------------------\n";


my $OIDbase = '1.3.6.1.2.1.2.2.1.14.';
my $OID;
my $row = 0;
my $col = 0;
my $noRows = 3;   # Number of Rows
my $noCols = 25;  # Number of Columns
my $result;
my @Error_Count = ( #IP ADDRESS, PORT: 1    2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20   21   22   23  24 
                  ["192.168.3.1",     "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0","0", "0", "0", "0", "0", "0", "0", "0", "0"],
                  ["192.168.3.2",     "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0","0", "0", "0", "0", "0", "0", "0", "0", "0"],
                  ["192.168.3.17",    "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0","0", "0", "0", "0", "0", "0", "0", "0", "0"]
                  );

 

  # Retrieve Data From Switches
   for($row = 0; $row<$noRows; $row++)
   {
	my ($session, $error) = Net::SNMP->session
	(
    	  -hostname  => shift || $Error_Count[$row][0],
     	  -timeout   => shift || 5, …
lAmoebal 1 Junior Poster in Training

That sounds like exactly how I started out.

My high school offered Pascal and C++ and I started out with Pascal and then took the C++ course before I moved on to doing it in college, and now trying to make a career out of it. :P

lAmoebal 1 Junior Poster in Training

This isn't a specific question regarding a certain program or anything, so if this is in the wrong forum, feel free to move it. :confused:

I was just curious how long everyone here has been programming, and how long with C++? The reason I'm asking is I'm curious as to how long it took people like Narue to become as proficient as they are with the language. :P

I personally have been programming for ~4 years now, and worked with C++ for probably about 2-3 of those years. About the first two years were all on really basic console programs since I took a C++ class in high school and my first few classes in college were basic C++ courses.


Edit - Since plgriffith posted the other languages he's worked with, I guess I will too.

I've also worked with some Pascal, Assembly, SQL, Java, PHP, HTML and now starting to play around with Perl a little at work. I haven't really gone in depth with any of these languages though, C++ has always been my main focus.

lAmoebal 1 Junior Poster in Training

i have one of that do you that just mail me or help me in my problem.... diz my e-add <snipped email>

Is this English?

lAmoebal 1 Junior Poster in Training

It's not unless you declared it elsewhere as one. I was going to tell you that.

lAmoebal 1 Junior Poster in Training

I believe that when you pass a 2D array you have to declare it as array[][5]...also, why did you put parens around your arrays?

Are you getting errors? What do they say?

And as Joatmon said, and I've said multiple times in this thread =P, add the brackets for the functions.

lAmoebal 1 Junior Poster in Training

I already downloaded a module that allows me to use the snmp functions, but it's just a matter of implementing them correctly that I have questions about. Unless you linked something completely different and I just missed the point. ><

lAmoebal 1 Junior Poster in Training

Also, this needs to be usable in both Windows and Solaris. I'm not familiar with Solaris, but would the open file command and such work with it?

Can you append to the beginning of a file too? Since this is going to be a diagnostic tool run like once a week, it would be better to have the newest dates at the top rather then the oldest.

lAmoebal 1 Junior Poster in Training

Here's more information on getchar() function http://www.cplusplus.com/reference/clibrary/cstdio/getchar.html

But basically it hangs there until the user presses enter. So it's more or less a 'Press any key to continue...' type thing when used like that.

lAmoebal 1 Junior Poster in Training

I'm not sure how you do it in Dev C++ actually. In VS you just click the grey space beside the line you want to add a break on, and whenever the program reaches that point, it pauses it where it is, so you can view all of the values of the variables and such and go through your program line by line to see how it executes.

lAmoebal 1 Junior Poster in Training

I'm not familiar with the function, but maybe try adding getchar(); right before the return statement? Or add a break there and see if it reaches the break before the song finishes playing. I would assume that the playsound command doesn't just cause the program to hang there until it's finished playing because that could cause problems.

lAmoebal 1 Junior Poster in Training

Hi guys, I'm writing a simple script that uses snmpget statements to check the errors received by ports on a router and have the results going to a file. I've never worked with Perl before but one of my coworkers had a really basic script that I've been trying to rework into something better suited to this and I have a few questions regarding it.

1. Is there a way to make the IP addresses and OID's dynamic? Could I do an snmpwalk or something similar until it didn't find an OID? The reason I'm asking is because we're going to need to put this script on many client's machines and want little to no configuration required.

2. As of now, if the snmpget command times out trying to reach a router, you have to wait ~10 seconds before it tries the next OID it's given. Is there a way to check if the host is available before? Or if the IP isn't available, read back in the output from the console window somehow and have a simple if/else statement to skip that router?


I think that's it for now. Here's a copy of the code that I have so far. Like I said, I've never worked with Perl, but it's what he had a simple script written in and I tried to port it to C++ but had LOTS of problems with snmp libraries and could never get them to link correctly. Any help …

lAmoebal 1 Junior Poster in Training

You could either just initialize everything to 0 before you pass it, and do the random generation in the function and replace the 0's, or you could just randomly generate the numbers before you pass the array to the function.


Edit - Off to grab lunch so if you ask a question, I won't be back for 30 minutes to answer. Just an FYI.

lAmoebal 1 Junior Poster in Training

Alright yeah, I'll probably just look into doing that and scrapping this whole snmp library thing. It's caused me nothing but problems since I've been trying to get a number of them working. =P

Thanks for your help guys, and advice.

lAmoebal 1 Junior Poster in Training

It's a little off. If you're going to pass an array in to the function, that's one thing, but if you do that, don't redeclare the array as you do on line 21. And if you're passing it in, you need to declare it before you do the passing in main. Your function calls in main are also off. You need to be setting them equal to something, or outputting them. If you're setting them equal, take off the endl at the end, and if you're outputting, add cout and the <<.

Also, you might want to consider actually making your array have a name that means something. It's trivial with a program this small, but it's good programming practice for once you get to writing larger programs.

lAmoebal 1 Junior Poster in Training

Yeah, there was a really basic PERL script that another guy here wrote a few months back which did the general thing that was wanted but since I've never worked with PERL I thought porting the script to C++ might be an easier alternative. Are PERL scripts compatible with Solaris? If so, maybe I'll just bite the bullet and try to edit his code to make it more functional. I'm assuming you can still write things to a file and such in PERL?

lAmoebal 1 Junior Poster in Training

You'd probably get better results if you made your whole post Bold, Italic, Underlined, and Bright Red. That way people know you mean business.

lAmoebal 1 Junior Poster in Training

1.) You want to create an array with 7 values (0-6) and fill it in a for loop. Then you can put the user question in a while loop. ie. while(ans!="No") and just pull which part of the array they ask for, but remember to subtract one since the array starts at 0. ie. Monday is 1 but for the array it would be array[0].
You could make a case statement for this if you wanted, or a bunch of if/elseif statements.


2) random number generator in a for loop from 0-9 that fills the array and then just have a for loop count back from 9-0 to print out backwards. can also use the mod operator % to divide by 2 and if there's no remainder add 1 to the total number of even numbers and then print it out after the loop.


I'm not writing the actual code for you, but if you make an attempt at it, I'll help. This is how you go about it though.

lAmoebal 1 Junior Poster in Training

I got the snmp++.lib to finally compile but it's only in the debug folder. Is this correct? My main program is still plagued with a bunch of linker errors.


The thing that sucks is our hardware supplier is already working on a fix or diagnostic program (I'm not sure which) for the media convertors which is what I'm creating a program to test. But since I'm still in training, my manager just wants me to mess around and see if I can get something working to refamiliarize myself with C++ and networking even though they won't ever use it.

lAmoebal 1 Junior Poster in Training

Judging from your error I'd say it's because you don't have the brackets for the function on line 8. Since you're not ready to use it yet, just comment that line out and see if it compiles.

lAmoebal 1 Junior Poster in Training

For one thing, it will probably complain about not having the brackets by the funtion on line 7. Even if nothing is being done in the function you need the open/close brackets and probably the return for it to compile.

Alternatively, if you're not ready to use that function, just comment that line out for now. Can you post the errors you're getting from the compiler?


And in order to post the code correctly, put [ code=cpp] at the beginning of your code and [/ code] at the end. Without the spaces after the first bracket.

lAmoebal 1 Junior Poster in Training

Putting your code in the

tags for readability.

[code=cpp]
#include <iostream>
//put additional include lines here as needed
//include <packageName>

using namespace std;

int cardNums(int array[5][5])
char bingoGrid(char bingoCard[5])

{

char bingoCard[5] {'B', 'I', 'N','G', 'O' }

{
int array[6][5];
for(int i = 0 ;i < 15 ; i++)
array[i] = 0;

srand((unsigned)time(0));
int random_integer;
int lowest=1, highest=15;
int range=(highest-lowest)+1;
for(int index=0; index<5; index++)
{
random_integer = lowest+rand()/(RAND_MAX/(highest-lowest) + 1);
if(array[random_integer-1] == 0) 
{
array[random_integer-1] = 1;
cout << random_integer << endl;
index++;
}

}
}
}

int main()
{
char bingoGrid(bingoCard)endl;
int cardNums(array [5][5])endl;






return 0;
}
lAmoebal 1 Junior Poster in Training

Unfortunately I'm not sure how to help you, but I think the loop idea is probably a bad one. Wouldn't that just eat up a bunch of system resources? You could maybe do a check every 5 minutes or something somehow, and if it passed the time and date, then do what the user entered. There are plenty of scheduling programs like this out there already though, why not just use one of them?

lAmoebal 1 Junior Poster in Training

I got these two errors when I tried to compile
C:\snmp_files\msvc\static\snmp++\snmp++.vcproj in visual c++ 2005.

1>..\..\..\snmp++\src\uxsnmp.cpp(719) : error C2065: 'm_hThread' : undeclared identifier
1>..\..\..\snmp++\src\uxsnmp.cpp(720) : error C2065: 'm_hThreadEndEvent' : undeclared identifier

Sigh, this is so frustrating that it's a prepackaged product and I can't get things to compile correctly.

EDIT - I fixed the problem. I forgot I had turned off thread support in one of the config files because we didn't want this program flooding the network with snmp requests so there was no need for threads, but I just turned it back on and it compiled.

Now to try the others... Thanks so far by the way.

lAmoebal 1 Junior Poster in Training
#include <iostream>

using namespace std;

int main()
{
	int i;
        int firstNum, secondNum;
        int evensum = 0;
        int oddsum = 0;

	cout << "Please enter 2 integers: ";
	cin >> firstNum >> secondNum;  //moved this here from
                                 //the loop so i got a value
        
        if (firstNum < secondNum)   //first num is smaller 
                                      //so i is first num
	    i = firstNum;                      
        else                       //else second num is smaller
          {
           i=secondNum;             //sets i to smaller number
           secondNum=firstNum;  //sets second number to larger number
           firstNum=i;         //copies smaller number from i
           }
	
	while (i <= secondNum) //needs to be <= so you get last number
	{		
		if ((i %2) == 0)           //if number is even
                  evensum += i;
		else              //not even, so it's odd
		  oddsum += i;
		i++;
	}
return 0;
}

There, I fixed the code you had and commented the fixes so you could follow. That should give you a start. It gets you the even/odd sum. If you need more help, let me know.

lAmoebal 1 Junior Poster in Training

Thanks, I'll try that when I get back to work tomorrow and let you know how it works out.

lAmoebal 1 Junior Poster in Training

Which do you need more help with?

And yeah Vmanes, I definitely meant that =P

lAmoebal 1 Junior Poster in Training

Correct me if I'm wrong, but it seems as though this is just the code that the professor gave to you, and it's all written out what to do in comments. Take a stab at it before just posting here and trying to get a solution.

lAmoebal 1 Junior Poster in Training

noOfGuesses isn't being set to anything before you're using it in the while loop so it doesn't know if it's less than 5 and it also can't add 1 to it

Exo1337 commented: Helpful +1
lAmoebal 1 Junior Poster in Training

When do you get the error? Also, could you please use the CODE tags from now on?

lAmoebal 1 Junior Poster in Training

Are you just trying to implement a simple sort of calendar program where the user enters a date and it says what information that is entered for that date, or are you trying to actually have the system automatically perform tasks once it reaches that date the user has entered information for?

lAmoebal 1 Junior Poster in Training

The only way to get better at programming is to work at it really. You can know every last piece of syntax, but if your logic is flawed, your programs will never run. And the reverse applies too. The only way to get better at either is to just practice, like anything.

lAmoebal 1 Junior Poster in Training

Prompts the user to input 2 integers firstNum and secondNum // Easy

Output all odd numbers between firstNum and secondNum // No idea how to start that.

Outputs the sum of all even numbers between firstNum and secondNum

Output the numbers and their squares between 1 and 10

Output the sum of the square of the Odd Numbers between firstNum and secondNum

These would all be easier to do with a for loop really, but if you're required to create a while loop, use this pseudocode to help..

while i < second num
{
//code
i++
}

In order to find if they're even numbers, use i%2 and if it equals 0, then it's even. Otherwise it's odd. A simple if/else can help there.

sum += sum + i;

Make sure you start sum at 0 before the loop.


I'm not sure I understand what the 'Output ALL Uppercase numbers' is?

lAmoebal 1 Junior Poster in Training

try

bigword = word1 + "_" + word2;

I'm fairly certain it will work. I'm a little rusty in my C++ syntax these days.

lAmoebal 1 Junior Poster in Training

try

mazefile.open(filename.c_str());
lAmoebal 1 Junior Poster in Training

I'm not sure how to do directly what you asked but if you put the information into a database, you can easily pull the information back out and populate the form with it using PHP.