Welcome, Guest. Please login or register.

Author Topic: My C homework  (Read 15885 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Mel's C homework
« Reply #59 from previous page: March 01, 2007, 08:30:21 PM »
Quote
I just wonder why you choose C, as that a language is old and on it's way out.

How is age of the language relevant? Regardless, C is not going anywhere.

IMO C is probably the best choice for overall programming skills. When you know C, it is easy to extend your knowlege to other languages.
 

Offline Linde

  • Sr. Member
  • ****
  • Join Date: Mar 2004
  • Posts: 457
    • Show only replies by Linde
    • http://hata.zor.org/
Re: Mel's C homework
« Reply #60 on: March 01, 2007, 08:42:11 PM »
Quote

IMO C is probably the best choice for overall programming skills. When you know C, it is easy to extend your knowlege to other languages.

I agree. With C behind me I could almost instantly pick up PHP and Javascript, and I bet that no "curly bracket" language is really out of my reach. I just need to read up on object orientation :)
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Mel's C homework
« Reply #61 on: March 01, 2007, 09:09:39 PM »
@guru-666
Quote
You guy's know that python has this kind of function built in already.

That doesn't help when learning C though.
 

Offline Dietmar

  • Full Member
  • ***
  • Join Date: Nov 2002
  • Posts: 220
    • Show only replies by Dietmar
    • http://devplex.awardspace.biz
Re: Mel's C homework
« Reply #62 on: March 01, 2007, 09:24:11 PM »
> I just wonder why you choose C, as that a language is old

As is English.
 

Offline guru-666

  • Hero Member
  • *****
  • Join Date: Dec 2006
  • Posts: 587
    • Show only replies by guru-666
Re: Mel's C homework
« Reply #63 on: March 01, 2007, 09:39:40 PM »
yes, english is very old, and a huge part of the world still uses it.   However it is evolving all the time, so learning old english first does not help you talk with people.
I guess learning C is a cool way to spend you free time if you have nothing else to do.  I still kind of want to learn ASM for 68000, but put it off becasue other than having fun there is no use I can think of.
Like I said before I suck at coding, but if I have an issue I can usualy get it resolved.  
Enjoy Mel's c homework, wonder if there would be half of the attention is she where a fat guy. LOL!
here is my take on it.
C, if you want to learn the ART of programing
Python, if you need to get the job done.

 

Offline Dietmar

  • Full Member
  • ***
  • Join Date: Nov 2002
  • Posts: 220
    • Show only replies by Dietmar
    • http://devplex.awardspace.biz
Re: Mel's C homework
« Reply #64 on: March 01, 2007, 09:41:41 PM »
> wonder if there would be half of the attention is she where a fat guy

Well, give it a try ;)
 

Offline guru-666

  • Hero Member
  • *****
  • Join Date: Dec 2006
  • Posts: 587
    • Show only replies by guru-666
Re: Mel's C homework
« Reply #65 on: March 01, 2007, 09:46:47 PM »
not fat.....sorry....maybe not even a guy, LOL
aber ich kann auch deutsch schreiben.
 

Offline AmireX

  • Jr. Member
  • **
  • Join Date: May 2005
  • Posts: 72
    • Show only replies by AmireX
Re: Mel's C homework
« Reply #66 on: March 01, 2007, 09:59:33 PM »
Quote

mel_zoom wrote:
As far as I understand Java, Perl, Python, PHP and all of the .net languages are all implemented in C at some level and cannot be built without it!

When everybody has forgotten C who will actually maintain the languages they have migrated to?


That's true. I use python a lot, but to integrate new functions into the language I often need to extend the interpreter with so called python dlls .. written in plain C ;-)

But at the other hand I try to not reinvent the wheel (is this correct english ??), so different languages for different tasks. But I like C/C++ too, it's like a good sudoku.
 

Offline guru-666

  • Hero Member
  • *****
  • Join Date: Dec 2006
  • Posts: 587
    • Show only replies by guru-666
Re: Mel's C homework
« Reply #67 on: March 01, 2007, 10:05:47 PM »
perfect english! well said.
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show only replies by mel_zoom
Re: Mel's C homework
« Reply #68 on: March 01, 2007, 10:07:39 PM »
Well Ive been trying to take in the hints from earlier about stage 3.

Its a bit confusing so far. I am guessing that the basic idea of building a list of words is no good?

I had thought of this:

Code: [Select]

struct uniqueword {
    struct uniqueword* last;
    struct uniqueord* next;
    const char* text;
    int count;
};


I think this solves the problem of not knowing how many unique words there are as you can add more uniqueword structures as you go along. I thought about having a list like this. Whenever you get a word you would walk along the list to see if you find it.

I thought that stricmp() could compare the word with the one in a structure until it finds the structure that contains the word already (or not). However it struck me that since stricmp() actually returns a value less than zero or greater than zero if one string is "less" than another or not that it could also be used to detect where in the list to add a new word. As long as the word in the structure is "less" than your current word then keep going along the list. If you then get to a word that is "greater" than your current one - assuming it didnt match anything - you could put your new word at that point in the list.

However I think I see the problem you are all hinting at. The more unique words there are the longer it takes to check if any word you are currently testing is there already. If there were very many unique words the program would run slower and slower.

Back to the drawing board?
I love my MX5!
Please pay a visit
 

Offline AmireX

  • Jr. Member
  • **
  • Join Date: May 2005
  • Posts: 72
    • Show only replies by AmireX
Re: Mel's C homework
« Reply #69 on: March 01, 2007, 10:07:58 PM »
Quote

guru-666 wrote:
perfect english! well said.


Danke, I'm learning.
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Mel's C homework
« Reply #70 on: March 01, 2007, 10:22:56 PM »
@mel_zoom

You got it right there. I think you should first implement it using the slow (list) method. When that works you can look into some faster ways to manage the words, such as trie, binary tree or hash table.

If you keep your program well structured, and separate the "lookup" and "insert" into separate routines you should have no problems changing the implementation when/if desired.

I do this quite a lot: I get all the simpler parts going first, and those work okay I tackle the bigger problem. It is easy to overwhelm yourself with tons of work, it helps if you keep things organized, and don't try to solve everything at once.

In my solution to stage 3 I have both binary tree and trie routines, toggleable with a #define. I could code the simple binary tree out of memory, and since I had set of simple functions for it, it was trivial to add conditional trie routines later on.

I guess what I am trying to say is: Don't be too hard on yourself and don't demand perfection from the beginning. Allow yourself to use simple(r) solutions, it is enough to recognize that better solutions exist. You can always improve the code after the basics work. (And in case you can't get the advanced solution working, at least you have the simpler one that DOES ;-))
 

Offline AmireX

  • Jr. Member
  • **
  • Join Date: May 2005
  • Posts: 72
    • Show only replies by AmireX
Re: Mel's C homework
« Reply #71 on: March 01, 2007, 10:24:07 PM »
To solve it in C (and not C++) you can use a hash function. Such a function calculates a special hash value (in a defined range) for every string. This value you can use to put the strings into an array. To avoid conflicts of equal hash values for different strings you built an array of linked lists and appends the equal strings to this lists.

Depending of the size of your "string list array" you have an access near to 1 O(1) to find a string.  But this is a hash map and always implemented in the standard template library for example.  :-?
 

Offline falemagn

  • Sr. Member
  • ****
  • Join Date: May 2002
  • Posts: 269
    • Show only replies by falemagn
    • http://www.aros.org/
Re: Mel's C homework
« Reply #72 on: March 02, 2007, 07:06:30 AM »
@ mel_zoom

Piru said all that I had in mind to reply myself, so... just wanted to say that I wish my coworkers were as skilled as a newbee like you is. ;-)
 

Offline mel_zoomTopic starter

  • Full Member
  • ***
  • Join Date: Jan 2007
  • Posts: 231
    • Show only replies by mel_zoom
Re: Mel's C homework
« Reply #73 on: March 02, 2007, 10:25:47 AM »
I have a good guru.
I love my MX5!
Please pay a visit
 

Offline A4000_Mad

  • Hero Member
  • *****
  • Join Date: Dec 2006
  • Posts: 1392
    • Show only replies by A4000_Mad
Re: Mel's C homework
« Reply #74 on: March 02, 2007, 10:34:04 AM »
Thanks Mel, I'm really getting to like this C stuff :-)

I must not mention the beautiful new avatar......
I must not mention the beautiful new avatar......
I must not mention the beautiful new avatar......
I must not mention the beautiful new avatar......
I must not mention the beautiful new avatar......

But wow!!


A4000 Mad
A4000 Mad