Please Help me solve these two questions

C

Common Man

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.
 
N

Noob

Common said:
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?
 
J

James Kuyper

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.
 
R

Rich Webb

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. ;-)
 
J

James Kuyper

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.
 
M

Mark Bluemel

Common said:
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).
 
C

Common Man

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.
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 (e-mail address removed)
 
E

Eric Sosman

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);
}
}
}
}
 
I

Ike Naar

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>.
 
M

Mark Bluemel

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.
 
C

Common Man

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

(e-mail address removed)

Thank You Eric Thank a Lot .
 
K

Keith Thompson

Common Man said:
Common said:
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.
 
A

Anand Hariharan

(..)
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
 
E

Eric Sosman

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 ...
 
J

James Kuyper

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.
 
K

Keith Thompson

Eric Sosman said:
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.
 
E

Eric Sosman

On 08/10/2012 02:59 PM, Eric Sosman wrote:
...

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.
 
8

88888 Dihedral

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top