I've been trying to learn C for quite a while. But I've had trouble
with the
lack of good quality online text (some of it's alright). But I finally
bought
a book on C, Practical C. I like it alot. I'm pretty familiar with the
C basics,
because I've been trying to learn it for a while. But anyone, I wrote
a program
to average any number of arguments given at the command line. I
thought it might
be useful to get feedback about my coding style or anything I've done
wrong. It
compile just fine with gcc (with -Wall -ansi -pedantic). Anyways, here
it is:
/* average.c - Average several numbers together. */
/* Copyright (C) 2003 Mark A. Nicolosi */
#include <stdio.h>
#include <malloc.h>
float average (int *numbers, int how_many);
int main (int argc, char **argv)
{
int how_many; /* Number of numbers to average. */
int i; /* Index for for loop. */
int *numbers; /* Array of numbers to be averaged. */
float answer; /* Variable to hold the answer. */
how_many = argc - 1; /* Every argument after argv[0] should be
number to average */
if (how_many == 0) /* If TRUE then not called with any arguments.
*/
{
printf ("Usage: %s <num1> <num2> ...\n", argv[0]);
return 1;
}
/* Allocate enough memory to hold the array of numbers to be
averaged. */
numbers = malloc (sizeof (int) * how_many);
/* Transfer the string arrays in argv[i + 1] to an array of
integars. */
for (i = 0; i < how_many; i++)
{
sscanf (argv[i + 1], "%d", &numbers[i]);
}
/* Now that we've got an array of integars to average, average 'em.
*/
answer = average (numbers, how_many);
printf ("%g\n", answer);
/* Free the array of numbers. */
free (numbers);
return 0;
}
float average (int *numbers, int how_many)
{
float answer = 0.0; /* Variable to hold the answer. */
int i; /* Index for for loop. */
/* Loop to add all the numbers in the number[] array. */
for (i = 0; i < how_many; i++)
{
answer = answer + numbers[i];
}
/* Now divide by the number of numbers. */
answer = answer / how_many;
return answer;
}
I copy and pasted that in to links, so I'm not sure if it'll look
alight :)
Thanks.
--
Mark A. Nicolosi 27 3065
Mark A. Nicolosi <ma****@foobox.net> wrote:
[...] /* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
#include <stdio.h> #include <malloc.h>
malloc.h is a non-standard header - to get a declaration of malloc, you
only need to #include <stdlib.h>.
float average (int *numbers, int how_many);
In general, you should choose "double" for floating point numbers,
unless you have a specific reason for choosing "float".
int main (int argc, char **argv) { int how_many; /* Number of numbers to average. */ int i; /* Index for for loop. */ int *numbers; /* Array of numbers to be averaged. */ float answer; /* Variable to hold the answer. */
how_many = argc - 1; /* Every argument after argv[0] should be number to average */ if (how_many == 0) /* If TRUE then not called with any arguments. */
It is possible for argc to be zero, in which case this if branch will
not be taken.
{ printf ("Usage: %s <num1> <num2> ...\n", argv[0]);
....which is a good thing, because in that case argv[0] would be NULL and
you would have a problem here.
return 1; }
/* Allocate enough memory to hold the array of numbers to be averaged. */ numbers = malloc (sizeof (int) * how_many);
You should check for malloc() returning NULL here, and report an error.
As your program is currently written, if malloc fails, it will still try
to access memory through the pointer "numbers".
/* Transfer the string arrays in argv[i + 1] to an array of integars. */ for (i = 0; i < how_many; i++) { sscanf (argv[i + 1], "%d", &numbers[i]); }
You should check that the return value of sscanf - it tells you if it
successfully performed the conversion. If it didn't, the value in
numbers[i] will be garbage, leading to a garbage result (formally, the
behaviour of the program in this instance is undefined, because it uses
an indeterminate value in a calculation).
Alternatively you can pre-fill the numbers array with 0.0 values.
/* Now that we've got an array of integars to average, average 'em. */ answer = average (numbers, how_many); printf ("%g\n", answer);
/* Free the array of numbers. */
free (numbers);
return 0; }
float average (int *numbers, int how_many) { float answer = 0.0; /* Variable to hold the answer. */ int i; /* Index for for loop. */
/* Loop to add all the numbers in the number[] array. */ for (i = 0; i < how_many; i++) { answer = answer + numbers[i]; }
/* Now divide by the number of numbers. */ answer = answer / how_many;
return answer; }
You can rewrite this program so that it doesn't need any dynamic memory
allocation at all, because you don't need to store every single number -
you can just keep a running total. Here is an alternative version of
your program, that uses the fact that the 'argv' array is terminated
with a NULL pointer:
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
double total = 0.0;
int how_many = 0;
int n;
while (*++argv) {
if (sscanf(*argv, "%d", &n) == 1) {
total += n;
how_many++;
}
}
if (how_many > 0) {
printf("%g\n", total / how_many);
return 0;
}
if (argv[0]) {
printf ("Usage: %s <num1> <num2> ...\n", argv[0]);
}
return 1;
}
Mark A. Nicolosi wrote: I've been trying to learn C for quite a while. But I've had trouble with the lack of good quality online text (some of it's alright). But I finally bought a book on C, Practical C. I like it alot. I'm pretty familiar with the C basics, because I've been trying to learn it for a while. But anyone, I wrote a program to average any number of arguments given at the command line. I thought it might be useful to get feedback about my coding style or anything I've done wrong. It compile just fine with gcc (with -Wall -ansi -pedantic). Anyways, here it is:
/* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
#include <stdio.h> #include <malloc.h>
float average (int *numbers, int how_many);
int main (int argc, char **argv) { int how_many; /* Number of numbers to average. */ int i; /* Index for for loop. */ int *numbers; /* Array of numbers to be averaged. */ float answer; /* Variable to hold the answer. */
how_many = argc - 1; /* Every argument after argv[0] should be number to average */ if (how_many == 0) /* If TRUE then not called with any arguments. */ { printf ("Usage: %s <num1> <num2> ...\n", argv[0]); return 1; }
/* Allocate enough memory to hold the array of numbers to be averaged. */ numbers = malloc (sizeof (int) * how_many);
/* Transfer the string arrays in argv[i + 1] to an array of integars. */ for (i = 0; i < how_many; i++) { sscanf (argv[i + 1], "%d", &numbers[i]); }
/* Now that we've got an array of integars to average, average 'em. */ answer = average (numbers, how_many); printf ("%g\n", answer);
/* Free the array of numbers. */
free (numbers);
return 0; }
float average (int *numbers, int how_many) { float answer = 0.0; /* Variable to hold the answer. */ int i; /* Index for for loop. */
/* Loop to add all the numbers in the number[] array. */ for (i = 0; i < how_many; i++) { answer = answer + numbers[i]; }
/* Now divide by the number of numbers. */ answer = answer / how_many;
return answer; }
I copy and pasted that in to links, so I'm not sure if it'll look alight :) Thanks.
It will work, but
1. better use atoi() than sscanf()
2. There are a lot of unnecessary manipulations, you really do not need to
allocate another array to compute the average. e.g.
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv)
{
int i, n;
float answer=0;
for (i=0; i < argc; i++)
answer = (answer*i+atoi(argv[i]))/(i+1);
printf (... answer ...);
return 0;
}
I wrote:
[...] #include <stdio.h> #include <stdlib.h>
int main (int argc, char **argv) { double total = 0.0; int how_many = 0; int n;
while (*++argv) {
Of course I made a classic blunder here - assuming that argc is greater
than 0. And I modify argv and then try to get the original argv[0]
later.
That should be
char *program;
if (argc < 2) {
if (argc < 1) {
program = "average";
} else {
program = argv[0];
}
printf ("Usage: %s <num1> <num2> ...\n", program);
return 1;
}
while (*++argv) {
/* ... */
Then remove the similar printf from the bottom.
- Kevin.
Rather ugly.
It will work, but
1. better use atoi() than sscanf()
2. There are a lot of unnecessary manipulations, you really do not need to
allocate another array to compute the average, e.g.
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv)
{
int i;
double answer=0;
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv)
{
int i;
double answer=0;
for (i=1; i < argc ; i++)
answer = (answer*(i-1)+atoi(argv[i]))/i;
printf ("answer %f\n", answer);
return 0;
}
/* sorry I had to repost; in first message the cycle started at 0
incorrectly */
Mark A. Nicolosi wrote: I've been trying to learn C for quite a while. But I've had trouble with the lack of good quality online text (some of it's alright). But I finally bought a book on C, Practical C. I like it alot. I'm pretty familiar with the C basics, because I've been trying to learn it for a while. But anyone, I wrote a program to average any number of arguments given at the command line. I thought it might be useful to get feedback about my coding style or anything I've done wrong. It compile just fine with gcc (with -Wall -ansi -pedantic). Anyways, here it is:
/* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
#include <stdio.h> #include <malloc.h>
float average (int *numbers, int how_many);
int main (int argc, char **argv) { int how_many; /* Number of numbers to average. */ int i; /* Index for for loop. */ int *numbers; /* Array of numbers to be averaged. */ float answer; /* Variable to hold the answer. */
how_many = argc - 1; /* Every argument after argv[0] should be number to average */ if (how_many == 0) /* If TRUE then not called with any arguments. */ { printf ("Usage: %s <num1> <num2> ...\n", argv[0]); return 1; }
/* Allocate enough memory to hold the array of numbers to be averaged. */ numbers = malloc (sizeof (int) * how_many);
/* Transfer the string arrays in argv[i + 1] to an array of integars. */ for (i = 0; i < how_many; i++) { sscanf (argv[i + 1], "%d", &numbers[i]); }
/* Now that we've got an array of integars to average, average 'em. */ answer = average (numbers, how_many); printf ("%g\n", answer);
/* Free the array of numbers. */
free (numbers);
return 0; }
float average (int *numbers, int how_many) { float answer = 0.0; /* Variable to hold the answer. */ int i; /* Index for for loop. */
/* Loop to add all the numbers in the number[] array. */ for (i = 0; i < how_many; i++) { answer = answer + numbers[i]; }
/* Now divide by the number of numbers. */ answer = answer / how_many;
return answer; }
I copy and pasted that in to links, so I'm not sure if it'll look alight :) Thanks.
It will work, but
1. better use atoi() than sscanf()
2. There are a lot of unnecessary manipulations, you really do not need to
allocate another array to compute the average. e.g.
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv)
{
int i;
float answer=0;
for (i=0; i < argc; i++)
answer = (answer*i+atoi(argv[i]))/(i+1);
printf (... answer ...);
return 0;
}
Mark A. Nicolosi wrote: I've been trying to learn C for quite a while. But I've had trouble with the lack of good quality online text (some of it's alright). But I finally bought a book on C, Practical C. I like it alot. I'm pretty familiar with the C basics, because I've been trying to learn it for a while. But anyone, I wrote a program to average any number of arguments given at the command line. I thought it might be useful to get feedback about my coding style or anything I've done wrong. It compile just fine with gcc (with -Wall -ansi -pedantic). Anyways, here it is:
/* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
#include <stdio.h> #include <malloc.h>
float average (int *numbers, int how_many);
int main (int argc, char **argv) { int how_many; /* Number of numbers to average. */ int i; /* Index for for loop. */ int *numbers; /* Array of numbers to be averaged. */ float answer; /* Variable to hold the answer. */
how_many = argc - 1; /* Every argument after argv[0] should be number to average */ if (how_many == 0) /* If TRUE then not called with any arguments. */ { printf ("Usage: %s <num1> <num2> ...\n", argv[0]); return 1; }
/* Allocate enough memory to hold the array of numbers to be averaged. */ numbers = malloc (sizeof (int) * how_many);
/* Transfer the string arrays in argv[i + 1] to an array of integars. */ for (i = 0; i < how_many; i++) { sscanf (argv[i + 1], "%d", &numbers[i]); }
/* Now that we've got an array of integars to average, average 'em. */ answer = average (numbers, how_many); printf ("%g\n", answer);
/* Free the array of numbers. */
free (numbers);
return 0; }
float average (int *numbers, int how_many) { float answer = 0.0; /* Variable to hold the answer. */ int i; /* Index for for loop. */
/* Loop to add all the numbers in the number[] array. */ for (i = 0; i < how_many; i++) { answer = answer + numbers[i]; }
/* Now divide by the number of numbers. */ answer = answer / how_many;
return answer; }
I copy and pasted that in to links, so I'm not sure if it'll look alight :) Thanks.
It will work, but
1. better use atoi() than sscanf()
2. There are a lot of unnecessary manipulations, you really do not need to
allocate another array to compute the average. e.g.
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv)
{
int i, n;
float answer=0;
for (i=0; i < argc; i++)
answer = (answer*i+atoi(argv[i]))/(i+1);
printf (... answer ...);
return 0;
}
I wrote:
[...] #include <stdio.h> #include <stdlib.h>
int main (int argc, char **argv) { double total = 0.0; int how_many = 0; int n;
while (*++argv) {
Of course I made a classic blunder here - assuming that argc is greater
than 0. And I modify argv and then try to get the original argv[0]
later.
That should be
char *program;
if (argc < 2) {
if (argc < 1) {
program = "average";
} else {
program = argv[0];
}
printf ("Usage: %s <num1> <num2> ...\n", program);
return 1;
}
while (*++argv) {
/* ... */
Then remove the similar printf from the bottom.
- Kevin.
Rather ugly.
It will work, but
1. better use atoi() than sscanf()
2. There are a lot of unnecessary manipulations, you really do not need to
allocate another array to compute the average, e.g.
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv)
{
int i;
double answer=0;
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv)
{
int i;
double answer=0;
for (i=1; i < argc ; i++)
answer = (answer*(i-1)+atoi(argv[i]))/i;
printf ("answer %f\n", answer);
return 0;
}
/* sorry I had to repost; in first message the cycle started at 0
incorrectly */
Mark A. Nicolosi wrote: I've been trying to learn C for quite a while. But I've had trouble with the lack of good quality online text (some of it's alright). But I finally bought a book on C, Practical C. I like it alot. I'm pretty familiar with the C basics, because I've been trying to learn it for a while. But anyone, I wrote a program to average any number of arguments given at the command line. I thought it might be useful to get feedback about my coding style or anything I've done wrong. It compile just fine with gcc (with -Wall -ansi -pedantic). Anyways, here it is:
/* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
#include <stdio.h> #include <malloc.h>
float average (int *numbers, int how_many);
int main (int argc, char **argv) { int how_many; /* Number of numbers to average. */ int i; /* Index for for loop. */ int *numbers; /* Array of numbers to be averaged. */ float answer; /* Variable to hold the answer. */
how_many = argc - 1; /* Every argument after argv[0] should be number to average */ if (how_many == 0) /* If TRUE then not called with any arguments. */ { printf ("Usage: %s <num1> <num2> ...\n", argv[0]); return 1; }
/* Allocate enough memory to hold the array of numbers to be averaged. */ numbers = malloc (sizeof (int) * how_many);
/* Transfer the string arrays in argv[i + 1] to an array of integars. */ for (i = 0; i < how_many; i++) { sscanf (argv[i + 1], "%d", &numbers[i]); }
/* Now that we've got an array of integars to average, average 'em. */ answer = average (numbers, how_many); printf ("%g\n", answer);
/* Free the array of numbers. */
free (numbers);
return 0; }
float average (int *numbers, int how_many) { float answer = 0.0; /* Variable to hold the answer. */ int i; /* Index for for loop. */
/* Loop to add all the numbers in the number[] array. */ for (i = 0; i < how_many; i++) { answer = answer + numbers[i]; }
/* Now divide by the number of numbers. */ answer = answer / how_many;
return answer; }
I copy and pasted that in to links, so I'm not sure if it'll look alight :) Thanks.
It will work, but
1. better use atoi() than sscanf()
2. There are a lot of unnecessary manipulations, you really do not need to
allocate another array to compute the average. e.g.
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char **argv)
{
int i;
float answer=0;
for (i=0; i < argc; i++)
answer = (answer*i+atoi(argv[i]))/(i+1);
printf (... answer ...);
return 0;
}
Isaac Mushinsky <im***@mail.ru> wrote: Rather ugly. It will work, but 1. better use atoi() than sscanf()
Nit: Better use strtol() than atoi(). :-)
<SNIP>
--
6 * 9 = 42 (base 13)
Mark A. Nicolosi wrote:
<snip> /* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
#include <stdio.h> #include <malloc.h>
float average (int *numbers, int how_many);
int main (int argc, char **argv) { int how_many; /* Number of numbers to average. */ int i; /* Index for for loop. */
I'd make these unsigned int since they can't be negative.
int *numbers; /* Array of numbers to be averaged. */ float answer; /* Variable to hold the answer. */
how_many = argc - 1; /* Every argument after argv[0] should be number to average */ if (how_many == 0) /* If TRUE then not called with any arguments. */
I'd test for argc == 1 before the first assignment. Just a tiny
efficiency tweak for the error case.
{ printf ("Usage: %s <num1> <num2> ...\n", argv[0]); return 1; }
/* Allocate enough memory to hold the array of numbers to be averaged. */ numbers = malloc (sizeof (int) * how_many);
Test for failure, i.e. numbers being NULL. /* Transfer the string arrays in argv[i + 1] to an array of integars. */ for (i = 0; i < how_many; i++) { sscanf (argv[i + 1], "%d", &numbers[i]);
Instead of incrementing i every time through the loop in argv[i + 1],
either start i at 1 and make the test for <= how_many or move the "i++"
to the first statement within the loop rather than at the end of the
"for..." line.
}
<snip>
float average (int *numbers, int how_many)
unsigned int how_many
{ float answer = 0.0; /* Variable to hold the answer. */ int i; /* Index for for loop. */
unsigned int i.
<snip>
Regards,
Ed.
"Mark A. Nicolosi" wrote:
.... snip ... /* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
I wouldn't dare to quote it in full with the above copyright
statement. A more suitable statement for use here might be
"Public domain, by ...".
--
Replies should be to the newsgroup
Chuck Falconer, on vacation.
LibraryUser <de**********@made.invalid> writes: "Mark A. Nicolosi" wrote: ... snip ... /* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
I wouldn't dare to quote it in full with the above copyright statement.
In Berne Convention member countries (i.e., almost everywhere), a work
is copyrighted with or without an explict copyright notice.
A more suitable statement for use here might be "Public domain, by ...".
I agree that everyone who posts any example program but the most trivial
should probably explicitly allow people to quote it and try it on their
own computers.
However, the presence or absence of a copyright notice doesn't make any
difference.
Martin
Isaac Mushinsky <im***@mail.ru> wrote: Rather ugly. It will work, but 1. better use atoi() than sscanf()
Nit: Better use strtol() than atoi(). :-)
<SNIP>
--
6 * 9 = 42 (base 13)
Mark A. Nicolosi wrote:
<snip> /* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
#include <stdio.h> #include <malloc.h>
float average (int *numbers, int how_many);
int main (int argc, char **argv) { int how_many; /* Number of numbers to average. */ int i; /* Index for for loop. */
I'd make these unsigned int since they can't be negative.
int *numbers; /* Array of numbers to be averaged. */ float answer; /* Variable to hold the answer. */
how_many = argc - 1; /* Every argument after argv[0] should be number to average */ if (how_many == 0) /* If TRUE then not called with any arguments. */
I'd test for argc == 1 before the first assignment. Just a tiny
efficiency tweak for the error case.
{ printf ("Usage: %s <num1> <num2> ...\n", argv[0]); return 1; }
/* Allocate enough memory to hold the array of numbers to be averaged. */ numbers = malloc (sizeof (int) * how_many);
Test for failure, i.e. numbers being NULL. /* Transfer the string arrays in argv[i + 1] to an array of integars. */ for (i = 0; i < how_many; i++) { sscanf (argv[i + 1], "%d", &numbers[i]);
Instead of incrementing i every time through the loop in argv[i + 1],
either start i at 1 and make the test for <= how_many or move the "i++"
to the first statement within the loop rather than at the end of the
"for..." line.
}
<snip>
float average (int *numbers, int how_many)
unsigned int how_many
{ float answer = 0.0; /* Variable to hold the answer. */ int i; /* Index for for loop. */
unsigned int i.
<snip>
Regards,
Ed.
"Mark A. Nicolosi" wrote:
.... snip ... /* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
I wouldn't dare to quote it in full with the above copyright
statement. A more suitable statement for use here might be
"Public domain, by ...".
--
Replies should be to the newsgroup
Chuck Falconer, on vacation.
LibraryUser <de**********@made.invalid> writes: "Mark A. Nicolosi" wrote: ... snip ... /* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
I wouldn't dare to quote it in full with the above copyright statement.
In Berne Convention member countries (i.e., almost everywhere), a work
is copyrighted with or without an explict copyright notice.
A more suitable statement for use here might be "Public domain, by ...".
I agree that everyone who posts any example program but the most trivial
should probably explicitly allow people to quote it and try it on their
own computers.
However, the presence or absence of a copyright notice doesn't make any
difference.
Martin
LibraryUser wrote: "Mark A. Nicolosi" wrote: ... snip ... /* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
I wouldn't dare to quote it in full with the above copyright statement. A more suitable statement for use here might be "Public domain, by ...".
As Martin pointed out, copyright applies whether this statement appears
or not. However, it's immaterial as quoting is allowed for the purpose
of commentary or criticism (Fair Use).
Brian Rodenborn
In article <3F***************@company.com>, Default User wrote: LibraryUser wrote: "Mark A. Nicolosi" wrote: > ... snip ... > > /* average.c - Average several numbers together. */ > /* Copyright (C) 2003 Mark A. Nicolosi */
I wouldn't dare to quote it in full with the above copyright statement. A more suitable statement for use here might be "Public domain, by ...".
As Martin pointed out, copyright applies whether this statement appears or not. However, it's immaterial as quoting is allowed for the purpose of commentary or criticism (Fair Use).
Uh oh.
Is there a standard C function that can help detect and prevent
copyright threads? ;-)
--
Neil Cerutti
Neil Cerutti <ho*****@yahoo.com> writes: Is there a standard C function that can help detect and prevent copyright threads? ;-)
Standard C does not support threads. You will have to use a
platform-specific library, and as such you should consult a
platform-specific newsgroup.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Neil Cerutti wrote: Is there a standard C function that can help detect and prevent copyright threads? ;-)
I think gcc includes a function that will convert copyright threads
to copyleft threads. However, being cross-threaded, it will only
work with cross-compilation.
--
Tom Zych
This email address will expire at some point to thwart spammers.
Permanent address: echo 'g******@cbobk.pbz' | rot13
LibraryUser wrote: "Mark A. Nicolosi" wrote: ... snip ... /* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
I wouldn't dare to quote it in full with the above copyright statement. A more suitable statement for use here might be "Public domain, by ...".
As Martin pointed out, copyright applies whether this statement appears
or not. However, it's immaterial as quoting is allowed for the purpose
of commentary or criticism (Fair Use).
Brian Rodenborn
In article <3F***************@company.com>, Default User wrote: LibraryUser wrote: "Mark A. Nicolosi" wrote: > ... snip ... > > /* average.c - Average several numbers together. */ > /* Copyright (C) 2003 Mark A. Nicolosi */
I wouldn't dare to quote it in full with the above copyright statement. A more suitable statement for use here might be "Public domain, by ...".
As Martin pointed out, copyright applies whether this statement appears or not. However, it's immaterial as quoting is allowed for the purpose of commentary or criticism (Fair Use).
Uh oh.
Is there a standard C function that can help detect and prevent
copyright threads? ;-)
--
Neil Cerutti
Neil Cerutti <ho*****@yahoo.com> writes: Is there a standard C function that can help detect and prevent copyright threads? ;-)
Standard C does not support threads. You will have to use a
platform-specific library, and as such you should consult a
platform-specific newsgroup.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Neil Cerutti wrote: Is there a standard C function that can help detect and prevent copyright threads? ;-)
I think gcc includes a function that will convert copyright threads
to copyleft threads. However, being cross-threaded, it will only
work with cross-compilation.
--
Tom Zych
This email address will expire at some point to thwart spammers.
Permanent address: echo 'g******@cbobk.pbz' | rot13
Martin Dickopp wrote: LibraryUser <de**********@made.invalid> writes: "Mark A. Nicolosi" wrote: ... snip ... /* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
I wouldn't dare to quote it in full with the above copyright statement.
In Berne Convention member countries (i.e., almost everywhere), a work is copyrighted with or without an explict copyright notice.
A more suitable statement for use here might be "Public domain, by ...".
I agree that everyone who posts any example program but the most trivial should probably explicitly allow people to quote it and try it on their own computers.
However, the presence or absence of a copyright notice doesn't make any difference.
Maybe I am excessively subtle. I was trying to point out the
foolishness of the copyright statement in the first place.
--
Replies should be to the newsgroup
Chuck Falconer, on vacation.
Martin Dickopp wrote: LibraryUser <de**********@made.invalid> writes: "Mark A. Nicolosi" wrote: ... snip ... /* average.c - Average several numbers together. */ /* Copyright (C) 2003 Mark A. Nicolosi */
I wouldn't dare to quote it in full with the above copyright statement.
In Berne Convention member countries (i.e., almost everywhere), a work is copyrighted with or without an explict copyright notice.
A more suitable statement for use here might be "Public domain, by ...".
I agree that everyone who posts any example program but the most trivial should probably explicitly allow people to quote it and try it on their own computers.
However, the presence or absence of a copyright notice doesn't make any difference.
Maybe I am excessively subtle. I was trying to point out the
foolishness of the copyright statement in the first place.
--
Replies should be to the newsgroup
Chuck Falconer, on vacation. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Arvie |
last post by:
I need some advice guys.. I am proposing that we get someone to do a
complete audit/review of our Java application codebase, about 1000
JSPs/Servlets and 100 EJBs. If I get firms to submit...
|
by: andrew blah |
last post by:
Hello
I have recently released catchmail - a free (BSD license) open source
Python utility www.users.bigpond.net.au/mysite/catchmail.htm
This script processes in and outbound emails and stores...
|
by: Ben Hanson |
last post by:
I have created an open source Notepad program for Windows in C++ that allows
search and replace using regular expressions (and a few other extras). It
is located at...
|
by: Rotten Spice |
last post by:
Hello all,
I am still pretty new to Access but I do have a grasp on some basic
functions.
I am having a problem with averaging and I think I'm trying to do
something a little too complex and...
|
by: Adam Monsen |
last post by:
I kindly request a code review. If this is not an appropriate place
for my request, where might be?
Specific questions are in the QUESTIONS section of the code.
...
|
by: Eigenvector |
last post by:
My question is more generic, but it involves what I consider ANSI standard C
and portability.
I happen to be a system admin for multiple platforms and as such a lot of
the applications that my...
|
by: At_sea_with_C |
last post by:
Hello all,
Im some way in C and i have to start on C++ to. I want your opinions on
Teach yourself C++ in 21 days by Jessi Liberty. Can I go with it as my
first book are are there better ones?
...
|
by: maxx233 |
last post by:
Hello all,
I'm new to OO design and have a question regarding where I should place some code. Here's a simplified situation:
I'm making an app to do create, submit, and track employee reviews...
|
by: len |
last post by:
I have created the following program to read a text file which happens
to be a cobol filed definition. The program then outputs to a file
what is essentially a file which is a list definition...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |