Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Please Help me solve these two questions

Reply
Thread Tools

Please Help me solve these two questions

 
 
Mark Bluemel
Guest
Posts: n/a
 
      08-10-2012
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.
 
Reply With Quote
 
 
 
 
Common Man
Guest
Posts: n/a
 
      08-10-2012
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 .

 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      08-10-2012
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) kst- <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"
 
Reply With Quote
 
Anand Hariharan
Guest
Posts: n/a
 
      08-10-2012
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
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      08-10-2012
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
 
Reply With Quote
 
James Kuyper
Guest
Posts: n/a
 
      08-10-2012
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.

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      08-10-2012
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) kst- <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"
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      08-10-2012
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
 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      08-10-2012
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
 
Reply With Quote
 
88888 Dihedral
Guest
Posts: n/a
 
      08-11-2012
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to solve these equations vj C++ 9 09-23-2011 11:13 AM
Please Some One Solve This Two Question..i Will Be Very Thank Ful To It sohailkhan4444 General Computer Support 0 07-13-2009 03:34 PM
Please Some One Solve This Two Question..i Will Be Very Thank Ful To It sohailkhan4444 General Computer Support 0 07-13-2009 03:34 PM
Can anyone solve these problems?? Kevin Wainhouse Computer Information 3 10-23-2004 02:21 AM
please help solve these linked list and sscanf problems Andrej Hocevar C Programming 1 08-18-2003 08:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57