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.
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.
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.
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?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
That clarifies the requirements. What have you tried?
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; } }
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.
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.Originally Posted by nrcse
You should use strcmp to compare strings, e.g.,Originally Posted by nrcse
Notice the '\n' that is used to print a newline. You should #include <string.h> for strcmp.Code:char *word = strtok(line, " "); while (word) { if (strcmp(word, "This") == 0) { printf("This is a Pronoun\n"); } /* ... */ word = strtok(NULL, " "); }
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.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Why not complete your program yourself?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)