Ways to fill in missing code 
Author Message
 Ways to fill in missing code

I have a series of programs that I would statistically like to see how
they can be filled in for teaching purpouses. I have delimited the
areas that are in question with ???.

I work with solaris but almost anything could work.

   /*
   *   q2-f01.c -- demonstrates a memory mapped file.
   *   To run type: q2 number
   *   where number is the number of positions(bytes) from
   *   the start of the file, which is 0.
   *
   *   use od -c q2.fun | more to see the file in bytes.
   *
   *     You are to fill in the missing code which is indicated
   *     by 3 question marks. Do not forget to copy to your directory
   *     the file q2.fun.
   */

   #include  <stdio.h>
   #include  <stdlib.h>
   #include  <fcntl.h>
   #include  <unistd.h>
   #include  <sys/types.h>
   #include  <sys/mman.h>
   #include  <sys/stat.h>
   #include  <errno.h>

   int main(int argc, char *argv[])
   {
       int fd, offset;
       char *data;
       struct stat sbuf;

       if (argc != 2) {
           fprintf(stderr, "usage: q2 offset\n");
           exit(1);
       }

       if ((fd = open("q2.fun", O_RDONLY)) == -1) {
           perror("open");
           exit(1);
       }

       if (stat("q2.fun", ???) == -1) {
           perror("stat");
           exit(1);
       }

       offset = atoi(argv[1]);
       if (offset  < 0 || offset >  sbuf.st_size-1) {
           fprintf(stderr, "q2: offset must be in the range 0-%d\n",
   sbuf.st_size-1);
           exit(1);
       }

       if ((data = mmap(( ???, sbuf.st_size, ???, ???, fd, 0)) ==
(caddr_t)(-1)) {
           perror("mmap");
           exit(1);
       }

       printf("byte at offset %d is '%c'\n", offset, data[offset]);

       return 0;
   }



Sat, 28 Aug 2004 01:58:15 GMT  
 Ways to fill in missing code

Quote:

>I have a series of programs that I would statistically like to see how
>they can be filled in for teaching purpouses. I have delimited the
>areas that are in question with ???.

>I work with solaris but almost anything could work.

>   /*
>   *   q2-f01.c -- demonstrates a memory mapped file.
>   *   To run type: q2 number
>   *   where number is the number of positions(bytes) from
>   *   the start of the file, which is 0.
>   *
>   *   use od -c q2.fun | more to see the file in bytes.
>   *
>   *     You are to fill in the missing code which is indicated
>   *     by 3 question marks. Do not forget to copy to your directory
>   *     the file q2.fun.
>   */

>   #include  <stdio.h>
>   #include  <stdlib.h>
>   #include  <fcntl.h>
>   #include  <unistd.h>
>   #include  <sys/types.h>
>   #include  <sys/mman.h>
>   #include  <sys/stat.h>
>   #include  <errno.h>

>   int main(int argc, char *argv[])
>   {
>       int fd, offset;
>       char *data;
>       struct stat sbuf;

>       if (argc != 2) {
>           fprintf(stderr, "usage: q2 offset\n");
>           exit(1);
>       }

>       if ((fd = open("q2.fun", O_RDONLY)) == -1) {
>           perror("open");
>           exit(1);
>       }

>       if (stat("q2.fun", ???) == -1) {
>           perror("stat");
>           exit(1);
>       }

>       offset = atoi(argv[1]);
>       if (offset  < 0 || offset >  sbuf.st_size-1) {
>           fprintf(stderr, "q2: offset must be in the range 0-%d\n",
>   sbuf.st_size-1);
>           exit(1);
>       }

>       if ((data = mmap(( ???, sbuf.st_size, ???, ???, fd, 0)) ==
>(caddr_t)(-1)) {
>           perror("mmap");
>           exit(1);
>       }

>       printf("byte at offset %d is '%c'\n", offset, data[offset]);

>       return 0;
>   }

does anyone have any ideas?

this could really help.

-----=  Posted via Newsfeeds.Com, Uncensored Usenet News  =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
 Check out our new Unlimited Server. No Download or Time Limits!
-----==  Over 80,000 Newsgroups - 19 Different Servers!  ==-----



Sat, 28 Aug 2004 02:55:21 GMT  
 Ways to fill in missing code

Quote:

> I have a series of programs that I would statistically like to see how
> they can be filled in for teaching purpouses. I have delimited the
> areas that are in question with ???.

> I work with solaris but almost anything could work.

>    /*
>    *   q2-f01.c -- demonstrates a memory mapped file.
>    *   To run type: q2 number
>    *   where number is the number of positions(bytes) from
>    *   the start of the file, which is 0.
>    *
>    *   use od -c q2.fun | more to see the file in bytes.
>    *
>    *     You are to fill in the missing code which is indicated
>    *     by 3 question marks. Do not forget to copy to your directory
>    *     the file q2.fun.
>    */

>    #include  <stdio.h>
>    #include  <stdlib.h>
>    #include  <fcntl.h>
>    #include  <unistd.h>
>    #include  <sys/types.h>
>    #include  <sys/mman.h>
>    #include  <sys/stat.h>
>    #include  <errno.h>

You include headers that are not described by the C standard, so your post
is off topic for clc. The people over in comp.unix.programmer may know what
these headers provide. Be aware, people don't like doing homework on
usenet, so you should provide your solution in the post as well.
Tobias.


Sat, 28 Aug 2004 02:59:46 GMT  
 Ways to fill in missing code

Quote:


>> I have a series of programs that I would statistically like to see how
>> they can be filled in for teaching purpouses. I have delimited the
>> areas that are in question with ???.

>> I work with solaris but almost anything could work.

>>    /*
>>    *   q2-f01.c -- demonstrates a memory mapped file.
>>    *   To run type: q2 number
>>    *   where number is the number of positions(bytes) from
>>    *   the start of the file, which is 0.
>>    *
>>    *   use od -c q2.fun | more to see the file in bytes.
>>    *
>>    *     You are to fill in the missing code which is indicated
>>    *     by 3 question marks. Do not forget to copy to your directory
>>    *     the file q2.fun.
>>    */

>>    #include  <stdio.h>
>>    #include  <stdlib.h>
>>    #include  <fcntl.h>
>>    #include  <unistd.h>
>>    #include  <sys/types.h>
>>    #include  <sys/mman.h>
>>    #include  <sys/stat.h>
>>    #include  <errno.h>

>You include headers that are not described by the C standard, so your post
>is off topic for clc. The people over in comp.unix.programmer may know what
>these headers provide. Be aware, people don't like doing homework on
>usenet, so you should provide your solution in the post as well.
>Tobias.

thanks I'll check it there

-----=  Posted via Newsfeeds.Com, Uncensored Usenet News  =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
 Check out our new Unlimited Server. No Download or Time Limits!
-----==  Over 80,000 Newsgroups - 19 Different Servers!  ==-----



Sat, 28 Aug 2004 03:19:59 GMT  
 Ways to fill in missing code

Quote:

> I have a series of programs that I would statistically like to see how
> they can be filled in for teaching purpouses. I have delimited the
> areas that are in question with ???.

> I work with solaris but almost anything could work.

>    /*
>    *   q2-f01.c -- demonstrates a memory mapped file.
>    *   To run type: q2 number
>    *   where number is the number of positions(bytes) from
>    *   the start of the file, which is 0.
>    *
>    *   use od -c q2.fun | more to see the file in bytes.
>    *
>    *     You are to fill in the missing code which is indicated
>    *     by 3 question marks. Do not forget to copy to your directory
>    *     the file q2.fun.
>    */

>    #include  <stdio.h>
>    #include  <stdlib.h>
>    #include  <fcntl.h>
>    #include  <unistd.h>
>    #include  <sys/types.h>
>    #include  <sys/mman.h>
>    #include  <sys/stat.h>
>    #include  <errno.h>

>    int main(int argc, char *argv[])
>    {
>        int fd, offset;
>        char *data;
>        struct stat sbuf;

>        if (argc != 2) {
>            fprintf(stderr, "usage: q2 offset\n");
>            exit(1);
>        }

>        if ((fd = open("q2.fun", O_RDONLY)) == -1) {
>            perror("open");
>            exit(1);
>        }

>        if (stat("q2.fun", ???) == -1) {
>            perror("stat");
>            exit(1);
>        }

>        offset = atoi(argv[1]);
>        if (offset  < 0 || offset >  sbuf.st_size-1) {
>            fprintf(stderr, "q2: offset must be in the range 0-%d\n",
>    sbuf.st_size-1);
>            exit(1);
>        }

>        if ((data = mmap(( ???, sbuf.st_size, ???, ???, fd, 0)) ==
> (caddr_t)(-1)) {
>            perror("mmap");
>            exit(1);
>        }

>        printf("byte at offset %d is '%c'\n", offset, data[offset]);

>        return 0;
>    }

I suggest you start by making sure your programs are correct.  The
very presence of "exit(1);" statements means they are not, not to
mention the plethora of non-standard include files.  After that,
format them in a reasonable manner, which means shorter lines that
do not wrap.

Please don't teach your students these bad habits.

--

   Available for consulting/temporary embedded and systems.
   (Remove "XXXX" from reply address. yahoo works unmodified)



Sat, 28 Aug 2004 11:30:57 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. flood fill code

2. fill forms in IE5 by code (VC or VB)

3. fill forms in IE5 by code (VC or VB)

4. Newbie coding error, Missing .sbr file, hunhhh?

5. Missing */ at the end of a comment f______ over code

6. event template code generator missing?

7. Difference between two different ways of doing things

8. 3 ways to uppercase

9. complex numbers - most common ways?

10. Different ways of implementing a 2d array

11. Help with ideas, best ways etc...

12. Good ways to obfuscate/mangle strings?

 

 
Powered by phpBB® Forum Software