Results 1 to 15 of 15

Thread: 4 functions to implement :S

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    39

    4 functions to implement :S

    remove_eoln
    cleanup_input
    output_introduction
    match_template

    I need to implement those into a program. And I have no idea... Anyone who can help please. or link me to some tutorial... I tried searching on wikipedia and some pdf. no luck.

    I'm new at C. I use cygwin as compiler. where should I put the script file and is the .o file important?

  2. #2
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    Re: 4 functions to implement :S

    I don't recall C++ templates with those names...what language are those again?

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

  3. #3
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: 4 functions to implement :S

    I'm pretty sure this is a school assignment, and those are the names of the functions that need to be written by yourself. Terrible function names if I do say so myself..

    What exactly are you having trouble with?

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  4. #4
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: 4 functions to implement :S

    Actually, having looked at your other thread, it appears you're attempting to write a chat bot.

    I would suggest sticking to simple things to start off, and learn the language. Chat Bots are hard work, considering theres not only knowledge of the language to understand, but how chat bots and AI work (I mean, Eliza is just a chat bot that turns your question into a response, but still..).

    Start with something easier.

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    39

    Re: 4 functions to implement :S

    You're so right chemicalNova.
    Unfortunately I don't get to choose my assignment.

    the function remove_eoln() scans the nul-byte terminated character array, and replaces the first found newline or carriage return caracter with a nul-byte.

    I got something but I'm not sure.

  6. #6
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: 4 functions to implement :S

    Quote Originally Posted by yan03
    You're so right chemicalNova.
    Unfortunately I don't get to choose my assignment.

    the function remove_eoln() scans the nul-byte terminated character array, and replaces the first found newline or carriage return caracter with a nul-byte.

    I got something but I'm not sure.

    That sounds pretty easy to implement:

    Code:
    for(char* c = search_in; *c != NULL; c++)
    {
       // if *c is '\r' or '\n', set *c to NULL and break;
    }
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    39

    Re: 4 functions to implement :S

    Code:
    void remove_eoln(char line[])
    {
    
        int i;
        i = 0;
    
            while( line[i] != 0)
            {
                    if (line[i] == '\r' || line[i] == '\n')
                    {       
                    line[i] = 0;
                    }    
                    i++;
            }
    }
    Do you think mine will work?

  8. #8

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    39

    Re: 4 functions to implement :S

    Quote Originally Posted by sunburnt
    That sounds pretty easy to implement:

    Code:
    for(char* c = search_in; *c != NULL; c++)
    {
       // if *c is '\r' or '\n', set *c to NULL and break;
    }
    wow. should I use pointers too?

    why did you commen your if loop?

  9. #9
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: 4 functions to implement :S

    Quote Originally Posted by yan03
    wow. should I use pointers too?

    why did you commen your if loop?
    No, you don't need to use pointers.

    Your code looks like it should work fine, with the exception that it will replace every newline or carriage return, not just the first one. If you just want to replace the first one, you just need to add a "break;" inside your if statement.


    I commented the line out because it's not actually code, just what you would need to do inside the loop.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  10. #10

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    39

    Re: 4 functions to implement :S

    THE FUNCTION cleanup_input() RECEIVES A NUL-BYTE TERMINATED ARRAY OF
    CHARACTERS AND MODIFIES THE ARRAY'S CONTENTS FOR LATER PROCESSING.
    ALL ALPHABETIC CHARACTERS ARE CONVERTED TO LOWERCASE, ANY APOSTROPHES
    ARE PRESERVED, AND UNNECESSARY SPACES BETWEEN WORDS ARE REMOVED.
    FOR EXAMPLE, THE STRING

    " This isn't a very LONG sentence."

    WOULD BE CONVERTED TO

    "this isn't a very long sentence"

    THE FUNCTION RETURNS AS SOON AS A FULLSTOP ('.') IS DETECTED OR WHEN
    THE END OF THE STRING IS REACHED.

  11. #11

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    39

    Re: 4 functions to implement :S

    Quote Originally Posted by sunburnt
    No, you don't need to use pointers.

    Your code looks like it should work fine, with the exception that it will replace every newline or carriage return, not just the first one. If you just want to replace the first one, you just need to add a "break;" inside your if statement.


    I commented the line out because it's not actually code, just what you would need to do inside the loop.

    thx you. I would have done a silly mistake.
    why did you learn C by the way?

  12. #12

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    39

    Re: 4 functions to implement :S

    how do I convert a string into an integer? and how do I convert it back?
    I don't really understand how the atoi function work.
    The example I got is;
    /* atoi: convert s to integer */
    int atoi(char s[])
    {
    int i, n;
    n = 0;
    for (i = 0; s[i] >= '0' && s[i] <= '9'; ++i)
    n = 10 * n + (s[i] - '0');
    return n;
    }

  13. #13

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    39

    Re: 4 functions to implement :S

    I got this.... can someone please check if it is right?

    static void cleanup_input(char line[])
    {

    int i;
    i = 0;

    while ( i = 0; i < EOF; i++ )
    {
    while (line[i] >= 'A' || line [i] <='Z')
    {
    line[i] = line [i] - 'b' + 'B';
    i++;
    }
    while (line[i] == ' ' && line[i + 1] == ' ')
    {
    line[i + 1] = 0;
    }
    while (line[i] == ".")
    {
    break;
    }

    }
    }
    Last edited by yan03; Sep 2nd, 2007 at 03:59 PM.

  14. #14

    Thread Starter
    Member
    Join Date
    Jul 2007
    Posts
    39

    Re: 4 functions to implement :S

    Quote Originally Posted by sunburnt
    Your code looks like it should work fine, with the exception that it will replace every newline or carriage return, not just the first one. If you just want to replace the first one, you just need to add a "break;" inside your if statement.
    "break stops only the loop it’s in. It doesn’t break out of a nested loop, or a
    loop within a loop." in a C for dummies.
    it looks like break will end my if loop but the while loop will still go on and consequently the if loop will still search for carriage return or newline, am I right?

  15. #15
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403

    Re: 4 functions to implement :S

    Quote Originally Posted by yan03
    "break stops only the loop it’s in. It doesn’t break out of a nested loop, or a
    loop within a loop." in a C for dummies.
    it looks like break will end my if loop but the while loop will still go on and consequently the if loop will still search for carriage return or newline, am I right?

    This is true -- break will only break out of the current loop. However, an "if" block is not considered a loop, so
    Code:
    while(a)
    {
       if (b)
          break;
    }
    will cause you to break out of the while loop. Think about it logically -- if "break" applied to if statements, there would be no way to conditionally break out of a while loop.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

Posting Permissions

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



Click Here to Expand Forum to Full Width