Thread: DNA Program

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    1

    DNA Program

    Hey guys. I usually don't do this but I'm COMPLETELY stuck and have no idea what to do. Me and 4 of my friends can't get past where we are. I'm in an intro to C course in first year so this might not seem too difficult to most of you but it is to us :P. Anyways, what I'm trying to do is here: http://kold-fire.net/4c/ The .pdf is the problem, the dna.txt is the strand, and 4c.txt is what I've done so far. I'm using Pelles C if any of you need to know and any help would seriously be appreciated. Thanks.

  2. #2
    UCF Mystic_Skies's Avatar
    Join Date
    Oct 2004
    Posts
    33
    Instead of using an "if" statement for your menu why don't you try using the switch statement?
    Code:
    switch ( value ) 
    {
       case 1:
           /* some statements */
          break;
       case 2:
          /* some more statements to execute */
          break;
       case 3:
          /* you get the idea */
          break;
       default:
          /* else nothing equals the value */
    }

  3. #3
    Deleting... VOX's Avatar
    Join Date
    Oct 2004
    Location
    VA
    Posts
    94
    Well for the read_DNA() function you can use the toupper function to raise lowecase letters to uppercase. For an intro (I don't know how far in you are) it looks like this is advanced stuff, or at least requires a lot of thinking.

    The syntax for toupper(); is (name is the variable name)
    Code:
    name = toupper(name);
    it takes whatever is in "name" and turns it into uppercase. It then stuffs it into whatever you put into the parenthesis of toupper(). You might need the ctype.h header file for this function.

    also to change an entire string into uppercase use the strupr() function. Syntax is
    Code:
    strupr(variable);
    it does the same thing as toupper but does a whole string instead of a character and changes the contents of variable instead of copying them into another variable.

    You might need the string.h header file for the strupr(); function.

    As I have said before all of this and lots more are in the C: For Dummies Vol 1+2 books.

    For the match_DNA() function you can use strcmp() to compare two strings and if they match return a value of 1.
    Code:
    result = strcmp(string1,string2);
    What it does is compare string1 and string2. If they match, it sticks the value 1 into result, if they don't match, it sticks a 0 into result. You need string.h for this to work and anything pretty much that starts with a str.
    Last edited by VOX; 12-01-2004 at 06:41 PM.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by VOX
    also to change an entire string into uppercase use the strupr() function. Syntax is
    Code:
    strupr(variable);
    it does the same thing as toupper but does a whole string instead of a character and changes the contents of variable instead of copying them into another variable.

    You might need the string.h header file for the strupr(); function.

    As I have said before all of this and lots more are in the C: For Dummies Vol 1+2 books.
    Apparently missing from these books was the fact that strupr is not a standard function, and therefore not necessarily found in <string.h> or any other standard header.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by VOX
    What it does is compare string1 and string2. If they match, it sticks the value 1 into result, if they don't match, it sticks a 0 into result. You need string.h for this to work and anything pretty much that starts with a str.
    bzzzzzzzzzzat!

    Code:
           int strcmp(const char *s1, const char *s2);
    
           The  strcmp()  and  strncmp()  functions return an integer
           less than, equal to, or greater than zero if  s1  (or  the
           first  n bytes thereof) is found, respectively, to be less
           than, to match, or be greater than s2.
    So if they match it returns 0, not 1. And it doesn't ever have to return 1 at all. Any integer would be a valid return value, depending on the strings you pass to the function.
    If you understand what you're doing, you're not learning anything.

  6. #6
    Deleting... VOX's Avatar
    Join Date
    Oct 2004
    Location
    VA
    Posts
    94
    If your string.h doesn't have it, then you don't have it. My conio.h is missing some things others have, but my compiler also has some things that others don't, not all compilers have complete header files with all functions ever made.

    If you don't have the strupr() function make the string into an array. Then capitalize each element in a loop with toupper().
    Last edited by VOX; 12-02-2004 at 03:41 PM.

  7. #7
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Some compilers don't even have a conio.h. We try to stick to the standard unless it's not possible (e.g. socket programming, graphics, etc.) strupr() doesn't fall under the standard. Don't think of a string.h that doesn't have strupr() as beeing "incomplete". Think of a string.h that has strupr() as "extra and confusing to new C programmers that end up using a different compiler".
    If you understand what you're doing, you're not learning anything.

  8. #8
    Deleting... VOX's Avatar
    Join Date
    Oct 2004
    Location
    VA
    Posts
    94
    Nothing wrong with what I said. Unless you can think of another way besides manually assigning each element in an array with a new char, using toupper, or strupr, it's the only way to do it. And strupr is not confusing at all.
    Code:
    strupr(variable);
    is about as simple as it gets.

  9. #9
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by VOX
    If your string.h doesn't have it, then you don't have it. My conio.h is missing some things others have, but my compiler also has some things that others don't, not all compilers have complete header files with all functions ever made.
    No. That's wrong. Those compilers aren't "incomplete" as far as the language goes. conio.h is full of non-standard functions. Whatever wierd extra crap is added into your string.h is just that: wierd extra crap. It's not standard. Therefore, it doesn't really do any good to tell someone to use those functions, does it? Because their compiler may conform strictly to the C standard, and as such it wouldn't have all the non-standard stuff yours has.

    That doesn't mean their compiler is "missing some things". It means yours has bundled in some extra crap that while it may be useful for you, does absolutely no good for teaching someone C, because you can't suggest they use them, as they may not have them.

    Again, their compiler isn't "incomplete". Yours just has "extra crap".

    Thus, as it has been stated countless times on the boards, when telling someone how to do something, use standard functions. Then you don't have to worry about wasting everyone's time when they come back and say "I don't have that. What's wrong?"

    Quzah.
    Hope is the first step on the road to disappointment.

  10. #10
    Deleting... VOX's Avatar
    Join Date
    Oct 2004
    Location
    VA
    Posts
    94
    I had that same problem a while back with the function setcursortype(). I didn't have it, you all said my compiler was missing it. It's not standard, so it's extra crap. Don't do something and then get angry at someone else when they do the same thing.

    I never said any compilers were incomplete. I simply stated that if you don't have it, then your string.h doesn't have it there. If you have it, it can be used to your benefit. And what if they do have it? Then I just saved them the trouble of using something else that might take longer.
    Last edited by VOX; 12-02-2004 at 09:45 PM.

  11. #11
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Quote Originally Posted by VOX
    I never said any compilers were incomplete
    Quote Originally Posted by VOX
    not all compilers have complete header files
    To me, the opposite of complete is incomplete.
    If you understand what you're doing, you're not learning anything.

  12. #12
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Yeah. That's kinda why I quoted them. Maybe their grasp of the English language is as good as their understanding of the C language.

    Quzah.
    Hope is the first step on the road to disappointment.

  13. #13
    Deleting... VOX's Avatar
    Join Date
    Oct 2004
    Location
    VA
    Posts
    94
    I don't care what you think. You don't make the decision on if what I say is bad or not. I am just trying to help, if you don't like the way I do it, I believe you can go to hell. You don't hear rifter complaining of any problems do you? No. Am I trying to help him or you? Him. So shut up and stop commenting whenever I say something.

  14. #14
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    > So shut up and stop commenting whenever I say something.
    Well so long as it falls into the category of being either wrong or compiler specific, the chances of that are pretty close to zero.

    Everybody is free to read and correct (and re-correct) whatever is said, and just occasionally, even us oldies learn something new.

  15. #15
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by VOX
    You don't make the decision on if what I say is bad or not.
    I'd be pretty stupid if I let everyone else make that decision for me, wouldn't I? I guess you actually decide(3) to say something stupid, and I simply am more aware of the stupidity than you are. That is to say, you are ignorant to your own stupidity, where as I am not. To further the point, I, as well as everyone else decide(1b) that what you say is in fact stupid. Since it is apparently as I have decided(1b), that you have as good an understanding of the English language as you do the C language, I suggest(1) you read the provided links to expand your vocabulary. Or am I not allowed to suggest either?

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  2. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM