Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Alan Greenspan
Jun 17, 2001

Donald Duck posted:

The books listed were Code Complete and Practice of Programing, as well as the Art of Programming. Would all these books be useful for me? I imagine most of the Knuth book would be beyond me at this stage
Yes. And Probably.

quote:

Second question, pretty much everything we've done has been just in Java, with a tiny bit of C in one of my modules. I've picked up the K&R C book to help me learn C over the summer. Since I want to know more than just Java, what else is worth learning?

I'd try to get some clue about concepts instead of programming languages. In my opinion every CS students needs to read this. Since this book introduces all kinds of programming language concepts you can also use it to find out what to learn next.

Adbot
ADBOT LOVES YOU

Donald Duck
Apr 2, 2007

Alan Greenspan posted:

Yes. And Probably.


I'd try to get some clue about concepts instead of programming languages. In my opinion every CS students needs to read this. Since this book introduces all kinds of programming language concepts you can also use it to find out what to learn next.

How much should that book on average be? The only shop around here with it sells it at 170euro?

Edit: Checked amazon and its only 35 sterling, I know where I'll be getting it then.

Donald Duck fucked around with this message at 14:55 on Apr 26, 2008

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Donald Duck posted:

I was looking through this thread originally to find books to read, as a CS student. Found them on the first page, but just wanted to ask some questions. I'm just finishing my second year now.
The books listed were Code Complete and Practice of Programing, as well as the Art of Programming. Would all these books be useful for me? I imagine most of the Knuth book would be beyond me at this stage
Code Complete is important for everyone, but I think it's hard to appreciate until you've been out of school and working on a large project. After that, it's obviously a great book. Save the Knuth until after you've had a course in algorithms.

quote:

Second question, pretty much everything we've done has been just in Java, with a tiny bit of C in one of my modules. I've picked up the K&R C book to help me learn C over the summer. Since I want to know more than just Java, what else is worth learning?
What do you want to do? Different languages are recommended for different things. If you just want any second or third language, consider picking up one of Python, Perl or Ruby.

quote:

Edit: I was reading reviews on the Knuth books and saw they code in them is in MIX? This would make them pretty out dated would it not?
While individual sections of Knuth's books might fall out of date (e.g., the section on sorting data that's stored on a tape drive), the books themselves will never be outdated. The algorithms are what's important, not any specific implementation.

haveblue
Aug 15, 2005



Toilet Rascal

ultrafilter posted:

the section on sorting data that's stored on a tape drive

A general algorithm for sorting a dataset that will not fit in RAM might still have some applications. Never say never :shobon:

Donald Duck
Apr 2, 2007

ultrafilter posted:

Code Complete is important for everyone, but I think it's hard to appreciate until you've been out of school and working on a large project. After that, it's obviously a great book. Save the Knuth until after you've had a course in algorithms.

What do you want to do? Different languages are recommended for different things. If you just want any second or third language, consider picking up one of Python, Perl or Ruby.

While individual sections of Knuth's books might fall out of date (e.g., the section on sorting data that's stored on a tape drive), the books themselves will never be outdated. The algorithms are what's important, not any specific implementation.
All we've really done is Datastructures and Aglorithms in the second year, I'll take a look at them in the shop and see if theyre any use at the moment or not.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


HB posted:

A general algorithm for sorting a dataset that will not fit in RAM might still have some applications. Never say never :shobon:
Sure, but most storage devices these days give you random access, whereas a tape doesn't. Knuth himself says that the tape sorting algorithm is a waste of paper and he's cutting it out of the next printing of the volume that it's in.

Narpas
Mar 16, 2008
You hear the rumble of distant thunder... You feel that eating the little dog was a bad idea.
Dumb question: in a bash shell, how do I echo the bottom-most directory? That is to say,
code:
narpas@narpas-laptop:~/Desktop/4E/Folder A/FolderB$ pwd
/home/narpas/Desktop/4E/Folder A/FolderB
                                 ^^^^^^^
                               I need this
Edit: Oh. I just saw basename. Nevermind!

Narpas fucked around with this message at 00:25 on Apr 27, 2008

gotly
Oct 28, 2007
Economy-Sized
I'm taking a data structures class and we designed and implemented our own linked list. Now I'm trying to use the actual integrated LinkedList function in Java and I must be blind but I can't find the basic Next function that goes to the next item in the list in constant time.

There is a get(int) function but that runs through the list in linear time to find it.

hey wiz
Jun 18, 2005

Sounds like you want LinkedList.iterator().next();

Incoherence
May 22, 2004

POYO AND TEAR

gotly posted:

I'm taking a data structures class and we designed and implemented our own linked list. Now I'm trying to use the actual integrated LinkedList function in Java and I must be blind but I can't find the basic Next function that goes to the next item in the list in constant time.

There is a get(int) function but that runs through the list in linear time to find it.
I think the method you want is listIterator(int) to start, and then use iterator.next() and iterator.previous() from there.

Explanation: Your question assumes a composite list (or a C style linked list): that is, each LinkedList object represents one node (say, with a first and rest, or with a data and a next). Java's LinkedList is the whole list in one object. So Java collections, and for that matter C++ STL collections, use "iterators" to represent the idea of sequence. You get the iterator, then whatever sequence-dependent things you want to do you do to the iterator. (Or you use foreach, but foreach doesn't solve all your problems.)

gotly
Oct 28, 2007
Economy-Sized
That did it, thanks!

Gumbos
Jul 1, 2003

Oh gosh that's funny. That's really funny. Do you write your own material? Do you?
I am trying to write a program for a class, and I need to reverse a string in C++. I don't understand why the code below gives me a C3070 compiler error; the left and right side of the = sign are both string objects being accessed at a single point.

I've googled around for other ways of reversing a string, but most involve a recursive method I don't really understand, and doubt I am meant to for the 5th assignment of a introductory C++ class at a community college.

code:
               for (counter = 0; counter < input_String->Length; counter++)
   {
      count2 = input_String->Length - counter - 1;
      input_String[counter] = input_Copy[count2];
   }
This is the snippet that causes the error. Am I not allowed to change individual parts of a string in this way? Why not?
This is part of a visual C++ .net GUI program.

quickedit: Just to make sure its clear, the error occurs on line 4 of that code.

JoeNotCharles
Mar 3, 2005

Yet beyond each tree there are only more trees.
Should work. Are you sure inputString isn't declared "const"? (And this isn't in a const method?)

Googling C3070 turns up a C# error - are you using std::string or some Microsoft string class?

Gumbos
Jul 1, 2003

Oh gosh that's funny. That's really funny. Do you write your own material? Do you?
I am using Visual C++ windows forms application, which from what I've been told, is a .NET implemented in C++. Most code I've used from the MSDN for .NET C++ has worked fine, but http://msdn2.microsoft.com/en-us/library/system.string.copyto.aspx and http://msdn2.microsoft.com/en-us/library/czx8s9ts.aspx both don't compile. Since making my first post I tried using .ToString(); after each array call, but the output was the string in forward order. Here is my complete code for this method, as of now:
code:
private: void Reverse (String ^ input_String)
   {
      String ^ input_Copy = input_String;
      int counter = 0;
      int count2;
      for (counter = 0; counter < input_String->Length; counter++)
      {
         count2 = input_String->Length - counter - 1;
         input_String->Replace(input_String[counter], input_Copy[count2]);
         //input_String[counter].ToString() == input_Copy[count2].ToString(); //old version
      }
      label_Reverse->Text = "Reversed: " + input_String;
   }
Thanks for the help.

Gumbos fucked around with this message at 04:41 on Apr 29, 2008

Happy Forum Man
Mar 18, 2001

Gumbos posted:

I am using Visual C++ windows forms application, which from what I've been told, is a .NET implemented in C++. Most code I've used from the MSDN for .NET C++ has worked fine, but http://msdn2.microsoft.com/en-us/library/system.string.copyto.aspx and http://msdn2.microsoft.com/en-us/library/czx8s9ts.aspx both don't compile. Since making my first post I tried using .ToString(); after each array call, but the output was the string in forward order. Here is my complete code for this method, as of now:
code:
private: void Reverse (String ^ input_String)
   {
      String ^ input_Copy = input_String;
      int counter = 0;
      int count2;
      for (counter = 0; counter < input_String->Length; counter++)
      {
         count2 = input_String->Length - counter - 1;
         input_String->Replace(input_String[counter], input_Copy[count2]);
         //input_String[counter].ToString() == input_Copy[count2].ToString(); //old version
      }
      label_Reverse->Text = "Reversed: " + input_String;
   }
Thanks for the help.

Ah, you can't reverse a System.String in place because they are immutable e.g. read-only. Apparently, the fastest way to reverse a .net string is to convert it to an array, reverse that, and convert back but you will have to make a new object each time you convert.

EDIT: Also, C++/CLI in an introductory C++ course is retarded. Half of what you are learning is not even C++.

Happy Forum Man fucked around with this message at 07:47 on Apr 30, 2008

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
WTF does the ^ character mean? Is it supposed to be a better *?

zootm
Aug 8, 2006

We used to be better friends.

MEAT TREAT posted:

WTF does the ^ character mean? Is it supposed to be a better *?
I'm not very experienced with this, but I think it's a pointer to a managed object.

Gumbos
Jul 1, 2003

Oh gosh that's funny. That's really funny. Do you write your own material? Do you?
I'm personally not entirely sure either, all I know is that the console string with lower case S does not compile, the only way I can store strings is by using String ^. I actually managed to figure out a solution using += to just feed the letters into the label backwards, one letter at a time. However, that is only part of this assignment, and the last part has been stumping me for many hours now.

I am supposed to write out the inputted string in reverse word order, meaning "This is a string" would be returned as "string a is This". So far I have tried using nested for loops to count backwards and find a word, which I have defined as being anything between 2 spaces. I then use a third loop to count up from the position of the lower positioned space to the higher one, each time feeding the letter from that position of the string into the label.

Unfortunately, this is not what happens. Instead I get no output at all, despite the program compiling and running without any runtime errors. I'm not sure what is wrong with my logic.

code:
for (counter = input_String->Length-1; counter > -1; counter --) 
//counts down from first letter in string
   if (input_String[counter].ToString() == " ") 
   //finds first space, another loop so counter = end of word and second_counter = start of word
      for (second_counter = counter; second_counter > -1; second_counter--)
      {
         if (input_String[second_counter].ToString() == " ")
         {
         //found start of word, third for loop to count up and write out word
            for (upward_counter = second_counter; upward_counter < counter + 1; upward_counter++)
               label_WordReverse->Text += input_String[upward_counter];
            second_counter = -1; //to prevent duplicates in case of >2 words
         }
         else if (second_counter = 0)
         //this handles the very first word
         {
            for (upward_counter = 0; upward_counter < input_String->Length - 1; upward_counter++)
               {
                  label_WordReverse->Text += input_String[upward_counter];
                  if (input_String[upward_counter].ToString() == " ")
                     upward_counter = input_String->Length;
               }
         }
      }
}
Note that this code does not pull the very last word as well, but I have a separate simpler loop that finds the last space and pulls the words before it, which functions fine. I was planning to use them in conjunction - messy, but the best I can think of.

Also, this class is technically a console based introductory C++, it's online at the community college I go to, and the teacher offers writing these GUIs as an advanced option. I am trying to do it since I have some experience in java and C++ already, at least at the introductory loops and arrays level.

Also, Happy Forum Man, I have another version of the above code that dumps the string to a char array one letter at a time, but when I try to read anything straight out of the array it gives me the code number equivalent instead of the letter.

Thanks again for the help.

Gumbos fucked around with this message at 18:16 on Apr 30, 2008

shodanjr_gr
Nov 20, 2007
Im gonna be doing a small project for uni on steganography (which is the hiding of data into other data - in my case, its messages in images).

Ive been looking to find some spec sheets about the byte-level format of some popular image file formats (jpeg, bmp, gif etc).

Inform me goons, expand my brain!

chocojosh
Jun 9, 2007

D00D.

Gumbos posted:

I'm personally not entirely sure either, all I know is that the console string with lower case S does not compile, the only way I can store strings is by using String ^. I actually managed to figure out a solution using += to just feed the letters into the label backwards, one letter at a time. However, that is only part of this assignment, and the last part has been stumping me for many hours now.

I am supposed to write out the inputted string in reverse word order, meaning "This is a string" would be returned as "string a is This". So far I have tried using nested for loops to count backwards and find a word, which I have defined as being anything between 2 spaces. I then use a third loop to count up from the position of the lower positioned space to the higher one, each time feeding the letter from that position of the string into the label.

Unfortunately, this is not what happens. Instead I get no output at all, despite the program compiling and running without any runtime errors. I'm not sure what is wrong with my logic.

code:
for (counter = input_String->Length-1; counter > -1; counter --) 
//counts down from first letter in string
   if (input_String[counter].ToString() == " ") 
   //finds first space, another loop so counter = end of word and second_counter = start of word
      for (second_counter = counter; second_counter > -1; second_counter--)
      {
         if (input_String[second_counter].ToString() == " ")
         {
         //found start of word, third for loop to count up and write out word
            for (upward_counter = second_counter; upward_counter < counter + 1; upward_counter++)
               label_WordReverse->Text += input_String[upward_counter];
            second_counter = -1; //to prevent duplicates in case of >2 words
         }
         else if (second_counter = 0)
         //this handles the very first word
         {
            for (upward_counter = 0; upward_counter < input_String->Length - 1; upward_counter++)
               {
                  label_WordReverse->Text += input_String[upward_counter];
                  if (input_String[upward_counter].ToString() == " ")
                     upward_counter = input_String->Length;
               }
         }
      }
}
Note that this code does not pull the very last word as well, but I have a separate simpler loop that finds the last space and pulls the words before it, which functions fine. I was planning to use them in conjunction - messy, but the best I can think of.

Also, this class is technically a console based introductory C++, it's online at the community college I go to, and the teacher offers writing these GUIs as an advanced option. I am trying to do it since I have some experience in java and C++ already, at least at the introductory loops and arrays level.

Also, Happy Forum Man, I have another version of the above code that dumps the string to a char array one letter at a time, but when I try to read anything straight out of the array it gives me the code number equivalent instead of the letter.

Thanks again for the help.

To put the strings in reverse word order, why not just store all the words in an array of strings, then simply concatenate them in reverse order? I think that would be much easier, especially with one of the *hint* built-in string functions.

6174
Dec 4, 2004

shodanjr_gr posted:

Im gonna be doing a small project for uni on steganography (which is the hiding of data into other data - in my case, its messages in images).

Ive been looking to find some spec sheets about the byte-level format of some popular image file formats (jpeg, bmp, gif etc).

Inform me goons, expand my brain!

http://www.wotsit.org/

csammis
Aug 26, 2003

Mental Institution

This was the exact site I was thinking of to answer his question, but goddamn if I could remember the address and Googling wasn't helping :smith:

6174
Dec 4, 2004

csammis posted:

This was the exact site I was thinking of to answer his question, but goddamn if I could remember the address and Googling wasn't helping :smith:

I couldn't remember it offhand either, but it was #2 for "file specifications" at Google.

csammis
Aug 26, 2003

Mental Institution

6174 posted:

I couldn't remember it offhand either, but it was #2 for "file specifications" at Google.

Yeah yeah, I was looking for "image file formats"

zero0ne
Jul 20, 2007
Zero to the O N E
I'm Currently working on a Caller ID app in C# for Asterisk, and I'm trying to go the OOP route so I can get a good understanding of OOP and to refresh my coding abilities.

Anyway, My question is this:

I have a class that will be like "iskClient" and will take care of the connect() disconnect() Authenticate() functions; IE this object will be the one that is directly connected to the asterisk server via a TCP connection.

My plan was to also have a iskMonitor() function in this class that will just basically forward anything asterisk sends to this TCP connection onto another class that will take care of parsing it and separating it. (to events / action-response classes)

The idea was that the iskMonitor() function would be run within a separate thread, and just run endlessly until the application is closed or the connection is closed. and anytime it gets data from asterisk, it forwards it to whatever object is going to parse it (iskParseEng probably will be the name of the class)

I am just basically trying to keep all the TCP / asterisk connection isolated to one class.


suggestions? is it "bad programming" to do something like this?

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
If I have a class with 3 members: id, name, parentId, and I want to print out the hierarchy like:

something
-here
--there
--every
--where
-zing
--ding
---wing
-test
--this

How would I go about doing it? It seems like recursion would be appropriate here, but I have very little experience with recursion.

Incoherence
May 22, 2004

POYO AND TEAR

fletcher posted:

If I have a class with 3 members: id, name, parentId, and I want to print out the hierarchy like:

something
-here
--there
--every
--where
-zing
--ding
---wing
-test
--this

How would I go about doing it? It seems like recursion would be appropriate here, but I have very little experience with recursion.
You're not being clear on your problem. I am guessing that you have a map of IDs to these structures somewhere, and that id and parentId are keys into that map, thus forming some sort of N-tree of IDs. The thing I can't guess is whether you want to print the tree from children up (so, "here" would be the parent of "something") or from the parents down (so, "something" would be the parent of "here"). The latter is somewhat more complicated, since if you want to do that, what you really want is to know all children of a given parent, at which point you do a preorder tree traversal.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Incoherence posted:

You're not being clear on your problem. I am guessing that you have a map of IDs to these structures somewhere, and that id and parentId are keys into that map, thus forming some sort of N-tree of IDs. The thing I can't guess is whether you want to print the tree from children up (so, "here" would be the parent of "something") or from the parents down (so, "something" would be the parent of "here"). The latter is somewhat more complicated, since if you want to do that, what you really want is to know all children of a given parent, at which point you do a preorder tree traversal.

Sorry, I want to print the tree from the parents down

parent
-child1
--subchild1
--subchild2
-child2

Incoherence
May 22, 2004

POYO AND TEAR

fletcher posted:

Sorry, I want to print the tree from the parents down

parent
-child1
--subchild1
--subchild2
-child2
Now for the other questions: how are you mapping from ID to node, and what parts of the tree do you have references to? You've apparently built a tree with only upward branches, so in order to figure out how to invert the tree (so you can preorder traverse it) we sort of need to know what we're starting from.

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction
This is kind of a programming related question: Is there any way to identify the function called in a compiled module? Example, given this output from Process Monitor, can I find out what the functions are?

Alan Greenspan
Jun 17, 2001

Factor Mystic posted:

This is kind of a programming related question: Is there any way to identify the function called in a compiled module? Example, given this output from Process Monitor, can I find out what the functions are?



http://www.hex-rays.com/idapro/idadown.htm

Download either the free version 4.9 or the 5.2 trial. Load the DLL you want into IDA. Make sure to say "Yes" if IDA asks you to download debug information from the Microsoft server (not sure if 4.9 does that, at least the full version of 5.2 does that). In IDA hit "g" to enter the address of the function (like 0x77A99523). If you're at the start of a function now that's probably the function you're looking for (you can double-check using the method I describe in the next paragraph).

If you're not at the start of a function it's probably that the DLL file was loaded to another address in memory than suggested in its header. In that case scroll all the way up in IDA until you see the first offset of the file (say 77A90000). Add +0x9523 manually to that address. Now you should be at the function you're looking for. If not, ask back and describe your problems.

limip
Oct 24, 2003

Factor Mystic posted:

This is kind of a programming related question: Is there any way to identify the function called in a compiled module? Example, given this output from Process Monitor, can I find out what the functions are?



Not generally, but for most of those, you can use the Microsoft symbol server to resolve those.
http://support.microsoft.com/kb/311503

Process Monitor doesn't use the _NT_SYMBOL_PATH environment variable, though, so you'll have to configure it through Options->Configure Symbols. "Symbol paths:" is the same format as you would put in the _NT_SYMBOL_PATH variable. Also, for whatever reason the dbghelp.dll in Windows\System32 wasn't working for it, so I had to point it to the DbgHelp.dll from my Debugging Tools for Windows folder.

Plastic Jesus
Aug 26, 2006

I'm cranky most of the time.

Factor Mystic posted:

This is kind of a programming related question: Is there any way to identify the function called in a compiled module? Example, given this output from Process Monitor, can I find out what the functions are?

Do you want to know which functions an application is using in a DLL? dumpbin (which comes with Visual Studio) will dump imports for you. If you don't have VS installed, periscope can do the same thing.

Red Oktober
May 24, 2006

wiggly eyes!



fletcher posted:

Sorry, I want to print the tree from the parents down

parent
-child1
--subchild1
--subchild2
-child2

I'm not really sure what you're asking here, but I think you just want to do a depth first search and print each node the first time you reach it.

ndb
Aug 25, 2005

So any of you who have had experience using Hugs98 or at least WinHugs, what would be a "C stack overflow"? It's different from the standard overflow, that's all I know.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Clock Explosion posted:

So any of you who have had experience using Hugs98 or at least WinHugs, what would be a "C stack overflow"? It's different from the standard overflow, that's all I know.

Chances are you have a really big foldl somewhere that's exploding and causing a whole lot of unevaluated thunks to wind up being created all at once. Replace it with a foldr if you don't need left-associativity, or foldl' if you do.

I can't really give you much more help without seeing some code, though.

ndb
Aug 25, 2005

My mistake.

code:
nextGen :: World -> World
nextGen w = Wrld{pop = newPop, randomList = newRands, maxGens = (maxGens w),  gens = (gens w) + 1, bestSize = bestSize w,dataPairs = (dataPairs w)}
		where
		bS = bestSize w
		mRands = randomList w
		randsNeeded = bS * size
		newRands = drop randsNeeded (mRands)
		best = take bS (pop w)
		crossed = crossEnts best (take randsNeeded randomW) 
		mutated = mutateEnts (best ++ crossed) (take randsNeeded (mRands)) (take randsNeeded randomW)
		newPop = take bS ( qsort (setFitEntities (best ++ crossed ++ mutated) (dataPairs w)))
		size = length (snd (head newPop))
		randomW = randomInts (0,size-1) randsNeeded
This is essentially a work in progress. Essentially,we create a world of polynomials with an attatched fitness value and we are using regression(if that's the right term) to evolve a polynomial that fits inside dataPairs. This function obviously creates the next generation of the world.

Let's just say I'm going through this half blind.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
Can you also post your World datatype, please?

Edit: It would also be useful to know an initial World, and if you get the stack overflow on the first call to this function, or if it only happens after a lot of iterations.

Factor Mystic
Mar 20, 2006

Baby's First Post-Apocalyptic Fiction

limip posted:

Not generally, but for most of those, you can use the Microsoft symbol server to resolve those.
http://support.microsoft.com/kb/311503

Process Monitor doesn't use the _NT_SYMBOL_PATH environment variable, though, so you'll have to configure it through Options->Configure Symbols. "Symbol paths:" is the same format as you would put in the _NT_SYMBOL_PATH variable. Also, for whatever reason the dbghelp.dll in Windows\System32 wasn't working for it, so I had to point it to the DbgHelp.dll from my Debugging Tools for Windows folder.

This is fantastic. Thank you. Notes for posterity: apparently, the symbol path must be lower case. Also, the c:\windows\system32\dbghelp.dll doesn't support symbol service which is why the debugging tools one is needed.

Adbot
ADBOT LOVES YOU

clay
Feb 4, 2003

brakes? unnecessary
I have an 2d array set up like this in C:

code:
int *ary[1000];

for (i; i < 1000; ++i) {
    ary[i] = malloc(other_ary[i]);
}
And I want to set up the exact same thing using mmap. Any pointers on this?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply