Ways to fill in missing code
Author |
Message |
jhagg.. #1 / 5
|
 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 |
|
 |
John Do #2 / 5
|
 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 |
|
 |
Tobias Oe #3 / 5
|
 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 |
|
 |
John Do #4 / 5
|
 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 |
|
 |
CBFalcone #5 / 5
|
 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 |
|
|
|