Please Help me solve these two questions

Discussion in 'C Programming' started by Common Man, Aug 10, 2012.

  1. Common Man

    Common Man Guest

    Question Number 1
    Write 2 threads. A producer thread and a consumer thread.
    Thread 1: The producer thread will ask the user to enter something on the screen.It will take the user input and write it into a buffer.

    Thread 2: The consumer thread will read from this buffer and display what the user entered on the screen.

    Question number 2
    Sachin 12
    Clark 45

    1. Read all the data from data1.txt. This will contain name, age.
    2. When someone enter a name then print the corresponding age of that person.
    Common Man, Aug 10, 2012
    #1
    1. Advertising

  2. Common Man

    Noob Guest

    Common Man wrote:

    > Question Number 1
    > [...]
    > Question number 2
    > [...]


    Could you provide the email address of your instructor, so that
    we may send our answers directly to them?
    Noob, Aug 10, 2012
    #2
    1. Advertising

  3. Common Man

    Common Man Guest

    On Friday, August 10, 2012 5:48:37 PM UTC+5:30, Noob wrote:
    > Common Man wrote:
    >
    >
    >
    > > Question Number 1

    >
    > > [...]

    >
    > > Question number 2

    >
    > > [...]

    >
    >
    >
    > Could you provide the email address of your instructor, so that
    >
    > we may send our answers directly to them?


    Please Reply me here. I want to get some clarity.
    Common Man, Aug 10, 2012
    #3
  4. Common Man

    James Kuyper Guest

    On 08/10/2012 08:23 AM, Common Man wrote:
    > On Friday, August 10, 2012 5:48:37 PM UTC+5:30, Noob wrote:
    >> Common Man wrote:
    >>
    >>
    >>
    >>> Question Number 1

    >>
    >>> [...]

    >>
    >>> Question number 2

    >>
    >>> [...]

    >>
    >>
    >>
    >> Could you provide the email address of your instructor, so that
    >>
    >> we may send our answers directly to them?

    >
    > Please Reply me here. I want to get some clarity.


    I think Noob wants to make sure he gets the proper amount of credit for
    his contribution to your assignment, and is doubtful that that will
    happen unless he sends in his response directly.
    --
    James Kuyper
    James Kuyper, Aug 10, 2012
    #4
  5. Common Man

    Rich Webb Guest

    On Fri, 10 Aug 2012 05:23:01 -0700 (PDT), Common Man
    <> wrote:

    >On Friday, August 10, 2012 5:48:37 PM UTC+5:30, Noob wrote:
    >> Common Man wrote:
    >>
    >>
    >>
    >> > Question Number 1

    >>
    >> > [...]

    >>
    >> > Question number 2

    >>
    >> > [...]

    >>
    >>
    >>
    >> Could you provide the email address of your instructor, so that
    >>
    >> we may send our answers directly to them?

    >
    >Please Reply me here. I want to get some clarity.


    Show what you have already written and tried along with any diagnostics
    you receive as well as the results of the test runs of your code.

    People here will help but they won't do the work for you. At least, not
    for free. If you're willing to pay commercial rates then there may be
    some interest. ;-)

    --
    Rich Webb Norfolk, VA
    Rich Webb, Aug 10, 2012
    #5
  6. Common Man

    James Kuyper Guest

    On 08/10/2012 08:14 AM, Common Man wrote:
    > Question Number 1
    > Write 2 threads. A producer thread and a consumer thread.
    > Thread 1: The producer thread will ask the user to enter something on the screen.It will take the user input and write it into a buffer.
    >
    > Thread 2: The consumer thread will read from this buffer and display what the user entered on the screen.
    >
    > Question number 2
    > Sachin 12
    > Clark 45
    >
    > 1. Read all the data from data1.txt. This will contain name, age.
    > 2. When someone enter a name then print the corresponding age of that person.


    Labeling to the contrary notwithstanding, I see no questions, just
    instructions. Do you have any questions about those instructions? Would
    you care to give us those questions? A good starting point would be to
    show us the work you've already done to carry out those instructions.

    Note: you could combine the two assignments: The producer thread will
    ask the user to provide a name, the consumer thread will display the
    corresponding age.
    --
    James Kuyper
    James Kuyper, Aug 10, 2012
    #6
  7. Common Man

    Mark Bluemel Guest

    On 10/08/2012 13:23, Common Man wrote:
    > On Friday, August 10, 2012 5:48:37 PM UTC+5:30, Noob wrote:
    >> Common Man wrote:
    >>> Question Number 1
    >>> [...]
    >>> Question number 2
    >>> [...]


    >> Could you provide the email address of your instructor, so that
    >> we may send our answers directly to them?


    > Please Reply me here. I want to get some clarity.


    The original questions were perfectly clear - what is your problem with
    them?

    They seem a rather strange pair of questions to raise in a C newsgroup -
    the first requires functionality (threads) which is not part of the C
    standard, while the second should be relatively trivial (though it may
    have some issues about memory usage depending on the size of the input
    file).
    Mark Bluemel, Aug 10, 2012
    #7
  8. Common Man

    Common Man Guest

    On Friday, August 10, 2012 6:05:38 PM UTC+5:30, James Kuyper wrote:
    > On 08/10/2012 08:23 AM, Common Man wrote:
    >
    > > On Friday, August 10, 2012 5:48:37 PM UTC+5:30, Noob wrote:

    >
    > >> Common Man wrote:

    >
    > >>

    >
    > >>

    >
    > >>

    >
    > >>> Question Number 1

    >
    > >>

    >
    > >>> [...]

    >
    > >>

    >
    > >>> Question number 2

    >
    > >>

    >
    > >>> [...]

    >
    > >>

    >
    > >>

    >
    > >>

    >
    > >> Could you provide the email address of your instructor, so that

    >
    > >>

    >
    > >> we may send our answers directly to them?

    >
    > >

    >
    > > Please Reply me here. I want to get some clarity.

    >
    >
    >
    > I think Noob wants to make sure he gets the proper amount of credit for
    >
    > his contribution to your assignment, and is doubtful that that will
    >
    > happen unless he sends in his response directly.
    >
    > --
    >
    > James Kuyper

    I don't have any instructor. I'm learning by self. From the morning I'm trying to solve these two questions, found in book. All credit will obviously go to you. many sincere Thanks in advance. You can use this mail if you want
    Common Man, Aug 10, 2012
    #8
  9. Common Man

    Eric Sosman Guest

    On 8/10/2012 8:14 AM, Common Man wrote:
    > Question Number 1
    > Write 2 threads. A producer thread and a consumer thread.
    > Thread 1: The producer thread will ask the user to enter something on the screen.It will take the user input and write it into a buffer.
    >
    > Thread 2: The consumer thread will read from this buffer and display what the user entered on the screen.
    >
    > Question number 2
    > Sachin 12
    > Clark 45
    >
    > 1. Read all the data from data1.txt. This will contain name, age.
    > 2. When someone enter a name then print the corresponding age of that person.


    The very latest ("C11") Standard supports multi-threaded
    execution, but I don't have a C11-conforming compiler. So I'll
    skip Question Number 1 and just do Question number 2:

    #include <stdio.h>
    #include <stdlib.h>

    static void part1(void), part2a(void), part2b(void);

    int main(void)
    {
    part1();
    part2a();
    part2b();
    }

    // "1. Read all the data from data1.txt. This will contain name, age."
    static void part1(void)
    {
    int link;
    FILE *t= fopen("data1.txt", "r");
    while (t)
    if ((link = getc(t)) < 0 && (feof(t) | ferror(t))) {
    fclose(t);
    t = 0;
    }
    printf("Finished reading all the data from data1.txt.\n");
    }

    // "2. When someone enter a name..."
    static void part2a(void)
    {
    printf("Enter a name: ");
    fflush(stdout);
    for (int next; (next = getchar()) != '\n' && next >= 0; ++next);
    printf("Thank you.\n");
    }

    // "2. ... then print the corresponding age of that person."
    static void part2b(void)
    {
    printf("That person's age is");
    for (int d114; ; ++d114) {
    if ((d114 = rand() % 0200) > 0) {
    for (int d112 = d114; ;) {
    if ((d112 = d112 * 0x12d1 % 0177) == d114) {
    printf(" or possibly %d.\n", d112);
    return;
    }
    printf(" %d,", d112);
    }
    }
    }
    }


    --
    Eric Sosman
    d
    Eric Sosman, Aug 10, 2012
    #9
  10. Common Man

    Ike Naar Guest

    On 2012-08-10, Mark Bluemel <> wrote:
    > They seem a rather strange pair of questions to raise in a C newsgroup -
    > the first requires functionality (threads) which is not part of the C
    > standard [...]


    As of C2011, it is. See 7.26 Threads <threads.h>.
    Ike Naar, Aug 10, 2012
    #10
  11. Common Man

    Mark Bluemel Guest

    On 10/08/2012 14:57, Ike Naar wrote:
    > On 2012-08-10, Mark Bluemel <> wrote:
    >> They seem a rather strange pair of questions to raise in a C newsgroup -
    >> the first requires functionality (threads) which is not part of the C
    >> standard [...]

    >
    > As of C2011, it is. See 7.26 Threads <threads.h>.


    True, I'd forgotten.

    The likelihood of the OP having a C2011 implementation to hand seems
    fairly low, though.
    Mark Bluemel, Aug 10, 2012
    #11
  12. Common Man

    Common Man Guest

    On Friday, August 10, 2012 6:33:47 PM UTC+5:30, Eric Sosman wrote:
    > On 8/10/2012 8:14 AM, Common Man wrote:
    >
    > > Question Number 1

    >
    > > Write 2 threads. A producer thread and a consumer thread.

    >
    > > Thread 1: The producer thread will ask the user to enter something on the screen.It will take the user input and write it into a buffer.

    >
    > >

    >
    > > Thread 2: The consumer thread will read from this buffer and display what the user entered on the screen.

    >
    > >

    >
    > > Question number 2

    >
    > > Sachin 12

    >
    > > Clark 45

    >
    > >

    >
    > > 1. Read all the data from data1.txt. This will contain name, age.

    >
    > > 2. When someone enter a name then print the corresponding age of that person.

    >
    >
    >
    > The very latest ("C11") Standard supports multi-threaded
    >
    > execution, but I don't have a C11-conforming compiler. So I'll
    >
    > skip Question Number 1 and just do Question number 2:
    >
    >
    >
    > #include <stdio.h>
    >
    > #include <stdlib.h>
    >
    >
    >
    > static void part1(void), part2a(void), part2b(void);
    >
    >
    >
    > int main(void)
    >
    > {
    >
    > part1();
    >
    > part2a();
    >
    > part2b();
    >
    > }
    >
    >
    >
    > // "1. Read all the data from data1.txt. This will contain name, age."
    >
    > static void part1(void)
    >
    > {
    >
    > int link;
    >
    > FILE *t= fopen("data1.txt", "r");
    >
    > while (t)
    >
    > if ((link = getc(t)) < 0 && (feof(t) | ferror(t))) {
    >
    > fclose(t);
    >
    > t = 0;
    >
    > }
    >
    > printf("Finished reading all the data from data1.txt.\n");
    >
    > }
    >
    >
    >
    > // "2. When someone enter a name..."
    >
    > static void part2a(void)
    >
    > {
    >
    > printf("Enter a name: ");
    >
    > fflush(stdout);
    >
    > for (int next; (next = getchar()) != '\n' && next >= 0; ++next);
    >
    > printf("Thank you.\n");
    >
    > }
    >
    >
    >
    > // "2. ... then print the corresponding age of that person."
    >
    > static void part2b(void)
    >
    > {
    >
    > printf("That person's age is");
    >
    > for (int d114; ; ++d114) {
    >
    > if ((d114 = rand() % 0200) > 0) {
    >
    > for (int d112 = d114; ;) {
    >
    > if ((d112 = d112 * 0x12d1 % 0177) == d114) {
    >
    > printf(" or possibly %d.\n", d112);
    >
    > return;
    >
    > }
    >
    > printf(" %d,", d112);
    >
    > }
    >
    > }
    >
    > }
    >
    > }
    >
    >
    >
    >
    >
    > --
    >
    > Eric Sosman
    >
    > d


    Thank You Eric Thank a Lot .
    Common Man, Aug 10, 2012
    #12
  13. Common Man <> writes:
    > On Friday, August 10, 2012 5:48:37 PM UTC+5:30, Noob wrote:
    >> Common Man wrote:
    >>
    >> > Question Number 1

    >>
    >> > [...]

    >>
    >> > Question number 2

    >>
    >> > [...]

    >>
    >> Could you provide the email address of your instructor, so that
    >>
    >> we may send our answers directly to them?

    >
    > Please Reply me here. I want to get some clarity.


    You missed Noob's point.

    Your question looks very much like you're asking us to do your homework
    for you. You haven't shown us any of your own efforts to solve the
    problems; you've just presented the assigned questions and asked for
    help. In other words, you appear to be trying to cheat by getting other
    people to do your work for you, so that you can turn it in to your
    instructor and take credit as if you'd done it yourself.

    He wasn't expecting you to take him up on his offer; he was making a
    point about who should get credit for the work.

    You said later that this isn't class work, but that was not at all
    obvious from your original post.

    But even if you're studying on your own, asking for help here without
    *any* effort to solve the problem yourself is not a good way to learn.
    Try to come up with your own solution, and let us know if you have
    questions about code that *you've written*, and we'll be happy to help
    if we can.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Will write code for food.
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Aug 10, 2012
    #13
  14. On Aug 10, 12:50 pm, Common Man <>
    wrote:
    > On Friday, August 10, 2012 6:33:47 PM UTC+5:30, Eric Sosman wrote:

    (..)
    > > The very latest ("C11") Standard supports multi-threaded
    > > execution, but I don't have a C11-conforming compiler. So I'll
    > > skip Question Number 1 and just do Question number 2:

    (..)
    > > // "2. ... then print the corresponding age of that person."
    > > static void part2b(void)
    > > {
    > > printf("That person's age is");
    > > for (int d114; ; ++d114) {
    > > if ((d114 = rand() % 0200) > 0) {
    > > for (int d112 = d114; ;) {
    > > if ((d112 = d112 * 0x12d1 % 0177) == d114) {
    > > printf(" or possibly %d.\n", d112);
    > > return;
    > > }
    > > printf(" %d,", d112);
    > > }
    > > }
    > > }
    > > }

    (..)
    > Thank You Eric Thank a Lot .


    What did you learn from Eric's program? Please review Keith's and
    Rich's follow-ups to your reply to James' post.

    - Anand
    Anand Hariharan, Aug 10, 2012
    #14
  15. Common Man

    Eric Sosman Guest

    On 8/10/2012 2:52 PM, Anand Hariharan wrote:
    > On Aug 10, 12:50 pm, Common Man <>
    > wrote:
    >> On Friday, August 10, 2012 6:33:47 PM UTC+5:30, Eric Sosman wrote:

    > (..)
    >>> The very latest ("C11") Standard supports multi-threaded
    >>> execution, but I don't have a C11-conforming compiler. So I'll
    >>> skip Question Number 1 and just do Question number 2:

    > (..)
    >> Thank You Eric Thank a Lot .

    >
    > What did you learn from Eric's program? Please review Keith's and
    > Rich's follow-ups to your reply to James' post.


    What he's learned thus far is as nothing compared to what he'll
    learn when he gives my program to his professor ...

    --
    Eric Sosman
    d
    Eric Sosman, Aug 10, 2012
    #15
  16. Common Man

    James Kuyper Guest

    On 08/10/2012 02:59 PM, Eric Sosman wrote:
    ....
    > What he's learned thus far is as nothing compared to what he'll
    > learn when he gives my program to his professor ...


    Doing a test run will be a learning experience too, but for best results
    he should put that off until after he's turned it in.
    James Kuyper, Aug 10, 2012
    #16
  17. Eric Sosman <> writes:
    > On 8/10/2012 2:52 PM, Anand Hariharan wrote:
    >> On Aug 10, 12:50 pm, Common Man <>
    >> wrote:
    >>> On Friday, August 10, 2012 6:33:47 PM UTC+5:30, Eric Sosman wrote:

    >> (..)
    >>>> The very latest ("C11") Standard supports multi-threaded
    >>>> execution, but I don't have a C11-conforming compiler. So I'll
    >>>> skip Question Number 1 and just do Question number 2:

    >> (..)
    >>> Thank You Eric Thank a Lot .

    >>
    >> What did you learn from Eric's program? Please review Keith's and
    >> Rich's follow-ups to your reply to James' post.

    >
    > What he's learned thus far is as nothing compared to what he'll
    > learn when he gives my program to his professor ...


    He did say elsewhere in this thread that he's studying on his own from a
    book, not doing homework for a class.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Will write code for food.
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Aug 10, 2012
    #17
  18. Common Man

    Eric Sosman Guest

    On 8/10/2012 3:12 PM, James Kuyper wrote:
    > On 08/10/2012 02:59 PM, Eric Sosman wrote:
    > ...
    >> What he's learned thus far is as nothing compared to what he'll
    >> learn when he gives my program to his professor ...

    >
    > Doing a test run will be a learning experience too, but for best results
    > he should put that off until after he's turned it in.


    My hunch is that he knows little Latin, so even if someone
    said "pri memo dulus" to him he wouldn't understand.

    --
    Eric Sosman
    d
    Eric Sosman, Aug 10, 2012
    #18
  19. Common Man

    Eric Sosman Guest

    On 8/10/2012 3:17 PM, Keith Thompson wrote:
    > Eric Sosman <> writes:
    >>
    >> What he's learned thus far is as nothing compared to what he'll
    >> learn when he gives my program to his professor ...

    >
    > He did say elsewhere in this thread that he's studying on his own from a
    > book, not doing homework for a class.


    "... and I am Marie of Roumania."

    --
    Eric Sosman
    d
    Eric Sosman, Aug 10, 2012
    #19
  20. Common Manæ–¼ 2012å¹´8月10日星期五UTC+8下åˆ8時14分52秒寫é“:
    > Question Number 1
    >
    > Write 2 threads. A producer thread and a consumer thread.
    >
    > Thread 1: The producer thread will ask the user to enter something on thescreen.It will take the user input and write it into a buffer.
    >
    >
    >
    > Thread 2: The consumer thread will read from this buffer and display whatthe user entered on the screen.
    >
    >
    >
    > Question number 2
    >
    > Sachin 12
    >
    > Clark 45
    >
    >
    >
    > 1. Read all the data from data1.txt. This will contain name, age.
    >
    > 2. When someone enter a name then print the corresponding age of that person.


    This is trivial in C for a common memory buffer of known length
    to the two threads to be locked by the writer for bytes written, and to be read by another thread.
    88888 Dihedral, Aug 11, 2012
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KK
    Replies:
    2
    Views:
    550
    Big Brian
    Oct 14, 2003
  2. Andrej Hocevar
    Replies:
    1
    Views:
    480
    Nick Austin
    Aug 18, 2003
  3. vj
    Replies:
    9
    Views:
    579
    kanishkporwal
    Sep 23, 2011
  4. Julia Briggs
    Replies:
    1
    Views:
    70
    Chris
    Dec 15, 2003
  5. su29090

    Problems on these two questions

    su29090, Nov 19, 2012, in forum: Python
    Replies:
    9
    Views:
    605
    Neil Cerutti
    Nov 20, 2012
Loading...

Share This Page