Results 1 to 16 of 16

Thread: Does anybody have C programming experience?

  1. #1
    Go Colts! Shade's Avatar
    Join Date
    Jan 2004
    Age
    36
    Posts
    44,231

    Sports Logo Sports Logo Sports Logo

    Question Does anybody have C programming experience?

    I'm having some trouble with this algorithm:

    http://www.cs.iupui.edu/~n305/fall08...7NameGame.html

    Any help anyone could toss my way would be greatly appreciated. This doesn't seem like it should be that difficult, but I'm mostly having issues with splitting the string.

  2. #2
    Huge Member heywoode's Avatar
    Join Date
    Nov 2004
    Location
    Indiana
    Age
    45
    Posts
    6,334

    Default Re: Does anybody have C programming experience?

    Sorry dude.

    I've been laid.

    Can't help you.


    I feel for you though. Please don't be mad that I'm making light of your plight. (I'm a poet and didn't know it.)

    I'm just trying to get you in a better mood!



    RESIDENT COUNTING THREAD PHILOSOPHIZER

  3. #3
    Go Colts! Shade's Avatar
    Join Date
    Jan 2004
    Age
    36
    Posts
    44,231

    Sports Logo Sports Logo Sports Logo

    Default Re: Does anybody have C programming experience?

    That's okay, woodey. Once I saw that you were the one who posted, any hope I had that I would get any help went right out the window.

  4. #4
    flexible and robust SoupIsGood's Avatar
    Join Date
    Jun 2004
    Location
    Lappy Go Hucky
    Age
    26
    Posts
    17,540

    Default Re: Does anybody have C programming experience?

    I haven't programmed in 9 years, so take this for like way less than it's even worth, but... must the string be split? Seems like you could do an i++ thing and then use i to point where you need to in the array, and copy/edit it as needed? I'm probably talking outta my ***, ummm, something like if name[0] != 'b' then you do name[0] = 'b' and if name[0] = 'b' then do name[0] = ' ' (and then m, f, although you'd probably need to have these changes each be different variables so that you then printf them, which I don't even know it that's something you can do.) Does that even make sense?

    Blargh. I have no idea. I thought you were done w/ classes?
    Last edited by SoupIsGood; 12-09-2008 at 11:59 PM.
    You, Never? Did the Kenosha Kid?

  5. #5
    Team Raskolnikov's Avatar
    Join Date
    Aug 2005
    Location
    Ghent, Belgium
    Age
    29
    Posts
    4,596

    Default Re: Does anybody have C programming experience?

    Interesting problem. I program in C. I'm guessing you're using the string.h library for this? http://www.cplusplus.com/reference/clibrary/cstring/

    If not, you should. PM me your code if you have some specific problem.
    Word on the street is he doesn't want your money, he only wants to please your ears...
    Bum in Berlin on Myspace

  6. #6
    Team Raskolnikov's Avatar
    Join Date
    Aug 2005
    Location
    Ghent, Belgium
    Age
    29
    Posts
    4,596

    Default Re: Does anybody have C programming experience?

    Btw you can split a string with strcpy, well, that is to say get the rest of a string starting from a given point. Just give in (the address of) the starting point of your split as the source string. With strncpy, you can cut out any part of a string you want by adding the number of characters.
    Word on the street is he doesn't want your money, he only wants to please your ears...
    Bum in Berlin on Myspace

  7. #7
    Go Colts! Shade's Avatar
    Join Date
    Jan 2004
    Age
    36
    Posts
    44,231

    Sports Logo Sports Logo Sports Logo

    Default Re: Does anybody have C programming experience?

    Yeah, I'm using string.h, and I'm trying to use strncpy, but I'm really not all that knowledgable about mullti-dimensional arrays or pointers.

    Here's what I have so far:

    Code:
    #include 
    #include 
    int main()
    {
    char select;
    char name;
    printf ("%s\n", "1. Name Game", "2. Exit");
    scanf("%s\n", &select);
    printf("%s\n", "Please enter a first name: ");
    scanf("%s\n", &name);
    char str1[] = "&name";
    char str2[1];
    strcopy (str2, str1);
    printf ("%s\n", "&name!\n 
    &name, &name, bo Bstr1\n
    Bonana fanna fo Fstr1\n
    fee fi mo M&srt1, &name!");
    return 0;
    }
    I honestly have no idea if I'm even on the right track here.

  8. #8
    Administrator/ The Real Jay ChicagoJ's Avatar
    Join Date
    Jan 2004
    Location
    Chicago
    Age
    44
    Posts
    17,000

    Sports Logo Sports Logo Sports Logo

    Default Re: Does anybody have C programming experience?

    I took a class a couple of decades ago on Borland's C++.

    My professor told me I was programming in C-. By the end of the semester, I had fallen to D+.

    There is no punchline here. My GPA was the punching bag, however, and it was time to change majors...
    Why do the things that we treasure most, slip away in time
    Till to the music we grow deaf, to God's beauty blind
    Why do the things that connect us slowly pull us apart?
    Till we fall away in our own darkness, a stranger to our own hearts
    And life itself, rushing over me
    Life itself, the wind in black elms,
    Life itself in your heart and in your eyes, I can't make it without you


  9. #9

    Default Re: Does anybody have C programming experience?

    Quote Originally Posted by Shade View Post
    This quote is hidden because you are ignoring this member. Show Quote

    Code:
    #include 
    #include 
    int main()
    {
    char select;
    char name;
    printf ("%s\n", "1. Name Game", "2. Exit");
    scanf("%s\n", &select);
    printf("%s\n", "Please enter a first name: ");
    scanf("%s\n", &name);
    char str1[] = "&name";
    char str2[1];
    strcopy (str2, str1);
    printf ("%s\n", "&name!\n 
    &name, &name, bo Bstr1\n
    Bonana fanna fo Fstr1\n
    fee fi mo M&srt1, &name!");
    return 0;
    }
    Segmentation fault

  10. #10
    Member Doug's Avatar
    Join Date
    Jan 2004
    Posts
    3,627

    Default Re: Does anybody have C programming experience?

    Seriously, C is one of my favorites. I haven't used it in years, though. I kinda miss it.

    I'm busy (and tired) right now, but I'll take a look later if I get a chance.
    You're caught up in the Internet / you think it's such a great asset / but you're wrong, wrong, wrong
    All that fiber optic gear / still cannot take away the fear / like an island song

    - Jimmy Buffett

  11. #11
    Go Colts! Shade's Avatar
    Join Date
    Jan 2004
    Age
    36
    Posts
    44,231

    Sports Logo Sports Logo Sports Logo

    Default Re: Does anybody have C programming experience?

    Hmm...my #include statements don't show up on the board for some weird reason. They should be stdio.h, and string.h.

    strcopy should condense the string down to the first digit of the name, but I don't know how to get it split properly otherwise.

  12. #12
    Raw Talent Robertmto's Avatar
    Join Date
    Apr 2006
    Location
    The Nap
    Posts
    5,260
    Mood

    Sports Logo Sports Logo Sports Logo Sports Logo Sports Logo

    Default Re: Does anybody have C programming experience?

    my brain hurts
    STARBURY

    08 and Beyond

  13. #13
    Go Colts! Shade's Avatar
    Join Date
    Jan 2004
    Age
    36
    Posts
    44,231

    Sports Logo Sports Logo Sports Logo

    Default Re: Does anybody have C programming experience?

    Then imagine how I feel right now.

  14. #14
    Team Raskolnikov's Avatar
    Join Date
    Aug 2005
    Location
    Ghent, Belgium
    Age
    29
    Posts
    4,596

    Default Re: Does anybody have C programming experience?

    Yes, definitely segmentation fault. C works with memory allocation, that is you have to specify in advance how much memory you need. The easiest way to do this here for your strings is with a fixed number of characters, say char name[200]. Also, you're gonna need strcat to form the rhyme names. Plus strpbrk is a useful function to locate a character in a string. I think these are the main functions you need: strpbrk to find the first vowel if the word doesn't start with a B, F or M, strcpy to get the tail of the splitted string, and strcat to form the rhyme names.

    If you want, I'll post my solution later. Maybe tomorrow, probably Monday.
    Word on the street is he doesn't want your money, he only wants to please your ears...
    Bum in Berlin on Myspace

  15. #15
    Member Doug's Avatar
    Join Date
    Jan 2004
    Posts
    3,627

    Default Re: Does anybody have C programming experience?

    Just be careful...




    http://xkcd.com/
    You're caught up in the Internet / you think it's such a great asset / but you're wrong, wrong, wrong
    All that fiber optic gear / still cannot take away the fear / like an island song

    - Jimmy Buffett

  16. #16
    Team Raskolnikov's Avatar
    Join Date
    Aug 2005
    Location
    Ghent, Belgium
    Age
    29
    Posts
    4,596

    Default Re: Does anybody have C programming experience?

    Here's my solution. I'm sure it could be done more efficiently, but as far I know, it works. My unreadable libraries are stdio, string and ctype. The latter you need for the function tolower.

    PS You should play the game with Bart. It's fo funny.

    Code:
    #include 
    #include 
    #include 
    
    /* List of functions */
    void namegame(char* name);
    char* get_rhyme(char* name,char* rhyme,char a);
    int first_vowel(char* string);
    
    /* Main of the program. Loops over the namegame until the user exits. */
    int main(void)
    {
      int choice;
      char name[200];
    
      do{
        printf("1.Name Game, 2.Exit.\n");
        scanf("%d",&choice); 
    
        if(choice==1)
          {
        printf("Enter a name.\n");
        scanf("%s",name);
        namegame(name);  
          } 
      }
      while(choice==1);
    }
    
    /* Play the namegame */
    void namegame(char* name)
    {
      char rhyme[200];
    
      printf("%s!\n",name);
      /* First B */
      get_rhyme(name,rhyme,'B');
      printf("%s, %s %s Bonana fanna ",name,name,rhyme);
      /* Then F */
      get_rhyme(name,rhyme,'F');
      printf("%s\n",rhyme);
      /* Then M */
      get_rhyme(name,rhyme,'M');
      printf("Fee fy %s, %s!\n",rhyme,name);
    }
    
    /* Gives the rhyme for a given name and character, 
     * including the preceeding o-word. 
     * For instance, get_rhyme("Fred",'F') returns "Fo red"
     */
    char* get_rhyme(char* name,char* rhyme,char a)
    {
      char temp[200]={};
      char cut[200];
      int cutoff;
      char b;
    
      /* First letter is equal to a */
      if(name[0] == a)
        {
          cutoff = 1;
          b = a;
        }
      /* General case */
      else{
        cutoff = first_vowel(name);
        b = tolower(a);
      }
    
      /* o-word */
      temp[0] = b;
      strcat(temp,"o ");
      /* Actual rhyme */
      if(name[0] != a)
        temp[3] = a;
      strcat(temp,strcpy(cut,&name[cutoff]));
      
      strcpy(rhyme,temp);
    }
    
    /* Returns position of the first vowel in a string */
    int first_vowel(char* string)
    {
      char* vowels = "aeiou";
      return strcspn(string,vowels);
    }
    Last edited by Raskolnikov; 12-15-2008 at 09:15 AM.
    Word on the street is he doesn't want your money, he only wants to please your ears...
    Bum in Berlin on Myspace

Similar Threads

  1. Pacer Magic Experience
    By BobbyMac in forum Indiana Pacers
    Replies: 1
    Last Post: 11-30-2008, 02:30 AM
  2. Replies: 33
    Last Post: 03-22-2008, 07:38 AM
  3. CRM Software - Anyone Have Any Experience?
    By bellisimo in forum Market Square (General Non-Sports Discussion)
    Replies: 7
    Last Post: 12-18-2007, 07:17 AM
  4. OT - A little update on WIBC's programming change.
    By Tom White in forum Indiana Pacers
    Replies: 4
    Last Post: 12-08-2007, 06:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •