Thread: Line break when space and tell me what is its pats of speech c program.

  1. #1
    Registered User
    Join Date
    Jun 2015
    Posts
    4

    Unhappy Line break when space and tell me what is its pats of speech c program.

    Hi, I am a beginner at c program. I need a program of Line break when space and tell me what is its pats of speech c program.

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Welcome to the forum.

    Your question is not really clear, so please read this (don't take the title personally): How To Ask Questions The Smart Way

    If there's a language barrier, no big deal, just try your best to explain and we'll try our best to understand.

    Also, be sure to show your best attempts at solving the problem you're having (as per the homework policy) - and if posting code, be sure to use code tags.

  3. #3
    Registered User
    Join Date
    Jun 2015
    Posts
    4

    Smile Input and Output will be:

    Quote Originally Posted by Matticus View Post
    Welcome to the forum.

    Your question is not really clear, so please read this (don't take the title personally): How To Ask Questions The Smart Way

    If there's a language barrier, no big deal, just try your best to explain and we'll try our best to understand.

    Also, be sure to show your best attempts at solving the problem you're having (as per the homework policy) - and if posting code, be sure to use code tags.
    The Input is Like "This is me"

    Output will be:

    "
    This is a pronoun
    is is a verb
    me is a pronoun

    "

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Is this an exercise in the learning of C or in the learning of natural language processing?

    Are you already familiar with some other programming language, along with common algorithms and data structures?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    That clarifies the requirements. What have you tried?

  6. #6
    Registered User
    Join Date
    Jun 2015
    Posts
    4

    Smile Yes, Am learning c. This is what i tried. But it not work.

    Quote Originally Posted by laserlight View Post
    Is this an exercise in the learning of C or in the learning of natural language processing?

    Are you already familiar with some other programming language, along with common algorithms and data structures?
    Code:
    #include <stdio.h>
    #include <conio.h>
    int main(){
    {
      char st[] ="This is a line";
      char *ch;
      printf("Split \"%s\"\n", st);
      printf("\n");
      ch = strtok(st, " ");
      while (ch != NULL)
        {
            char aa[]=ch;
    
    
            if(aa[]="This")
            {
                printf("This is a Pronoun");
            }
    
    
    
    
    
    
            else if(aa[]="is")
            {
                printf("This is a Pronoun");
            }
    
    
            else if(aa[]="a")
            {
                printf("This is a article");
            }
    
    
            else if(aa[]="line")
            {
                printf("This is a noun");
            }
            break;
        }
      getch();
      return 0;
    }
    }

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    1. You don't need "conio.h" - it's outdated, and you aren't using it for anything (expect apparently to keep the console window open - see here for better alternatives: FAQ > Stop my Windows Console from disappearing everytime I run my program? - Cprogramming.com)

    2. A single = is used for assignment, whereas a double == is used to test for equality; but...

    3. You can't compare strings in C using == ... you need to use the string compare function "strcmp()"

    I haven't dug much deeper into the code you provided - start by fixing those things up and trying to compile, and check back with your updated code.

    In fact, I'd recommend starting over, and building your program gradually, testing as you go - see here: A development process

    I'm also pretty sure you need to develop a more general solution, instead of checking for the specific words in the given example.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by nrcse
    Yes, Am learning c.
    Ah, then yes, your idea of associating words with the part of speech tag without concern for context would be fine. In reality this does not always work, e.g., "work" in one context is a noun, in another it is an adjective or a verb.

    Quote Originally Posted by nrcse
    This is what i tried. But it not work.
    You should use strcmp to compare strings, e.g.,
    Code:
    char *word = strtok(line, " ");
    while (word)
    {
        if (strcmp(word, "This") == 0) {
            printf("This is a Pronoun\n");
        }
        /* ... */
        word = strtok(NULL, " ");
    }
    Notice the '\n' that is used to print a newline. You should #include <string.h> for strcmp.

    Furthermore, notice that I called strtok at the end of the loop body. Otherwise, you would never proceed to the next token. I have taken the liberty of renaming your variables: frankly, "st" and "aa" are poor variable names here as they are not descriptive.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Jun 2015
    Posts
    4

    Am failed.

    Quote Originally Posted by laserlight View Post
    Ah, then yes, your idea of associating words with the part of speech tag without concern for context would be fine. In reality this does not always work, e.g., "work" in one context is a noun, in another it is an adjective or a verb.


    You should use strcmp to compare strings, e.g.,
    Code:
    char *word = strtok(line, " ");
    while (word)
    {
        if (strcmp(word, "This") == 0) {
            printf("This is a Pronoun\n");
        }
        /* ... */
        word = strtok(NULL, " ");
    }
    Notice the '\n' that is used to print a newline. You should #include <string.h> for strcmp.

    Furthermore, notice that I called strtok at the end of the loop body. Otherwise, you would never proceed to the next token. I have taken the liberty of renaming your variables: frankly, "st" and "aa" are poor variable names here as they are not descriptive.

    Please can you provide me full code for that problem ?

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Why not complete your program yourself?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extra line break added during copying
    By Tigers! in forum C Programming
    Replies: 14
    Last Post: 10-21-2009, 04:49 AM
  2. line break issues
    By bbeltwilson in forum C++ Programming
    Replies: 5
    Last Post: 12-28-2008, 04:00 PM
  3. Pats vs Giants, the current score is...
    By Salem in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 02-07-2008, 03:25 PM
  4. [Weird Question] Where to break a line in C++ code?
    By meili100 in forum C++ Programming
    Replies: 13
    Last Post: 11-22-2007, 02:17 PM
  5. Read until line break
    By Crilston in forum C Programming
    Replies: 5
    Last Post: 03-24-2006, 02:35 PM

Tags for this Thread