Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #73834 > unrolled thread
| Started by | Alla _ <modelling.data@gmail.com> |
|---|---|
| First post | 2015-10-26 03:09 -0700 |
| Last post | 2015-10-26 10:43 -0700 |
| Articles | 20 on this page of 115 — 21 participants |
Back to article view | Back to comp.lang.c
Program to output initials of a name Alla _ <modelling.data@gmail.com> - 2015-10-26 03:09 -0700
Re: Program to output initials of a name Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-26 03:22 -0700
Re: Program to output initials of a name Alla _ <modelling.data@gmail.com> - 2015-10-26 05:32 -0700
Re: Program to output initials of a name Barry Schwarz <schwarzb@dqel.com> - 2015-10-26 14:34 -0700
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-26 10:38 +0000
Re: Program to output initials of a name Alla _ <modelling.data@gmail.com> - 2015-10-26 05:37 -0700
Re: Program to output initials of a name Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-26 13:53 +0000
Re: Program to output initials of a name Alla _ <modelling.data@gmail.com> - 2015-10-26 07:33 -0700
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-26 15:21 +0000
Re: Program to output initials of a name Bartc <bc@freeuk.com> - 2015-10-26 16:26 +0000
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-26 16:41 +0000
Re: Program to output initials of a name Geoff <geoff@invalid.invalid> - 2015-10-26 10:27 -0700
Re: Program to output initials of a name Bartc <bc@freeuk.com> - 2015-10-26 17:29 +0000
Re: Program to output initials of a name raltbos@xs4all.nl (Richard Bos) - 2015-11-10 15:40 +0000
Re: Program to output initials of a name Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-27 13:36 +0000
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-27 13:45 +0000
Re: Program to output initials of a name David Brown <david.brown@hesbynett.no> - 2015-10-27 15:10 +0100
Re: Program to output initials of a name Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-27 20:08 +0000
Re: Program to output initials of a name David Brown <david.brown@hesbynett.no> - 2015-10-27 22:28 +0100
Re: Program to output initials of a name Bartc <bc@freeuk.com> - 2015-10-27 21:34 +0000
Re: Program to output initials of a name David Brown <david.brown@hesbynett.no> - 2015-10-28 08:50 +0100
Re: Program to output initials of a name Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-28 15:19 +0000
Re: Program to output initials of a name David Brown <david.brown@hesbynett.no> - 2015-10-28 22:17 +0100
Re: Program to output initials of a name Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-29 19:54 +0000
Re: Program to output initials of a name David Brown <david.brown@hesbynett.no> - 2015-10-30 08:44 +0100
Re: Program to output initials of a name James Kuyper <jameskuyper@verizon.net> - 2015-10-30 13:44 -0400
Re: Program to output initials of a name guinness.tony@gmail.com - 2015-10-28 04:19 -0700
Re: Program to output initials of a name David Brown <david.brown@hesbynett.no> - 2015-10-28 12:50 +0100
Re: Program to output initials of a name guinness.tony@gmail.com - 2015-10-28 08:19 -0700
Re: Program to output initials of a name guinness.tony@gmail.com - 2015-10-28 10:21 -0700
Re: Program to output initials of a name David Brown <david.brown@hesbynett.no> - 2015-10-28 22:34 +0100
Re: Program to output initials of a name raltbos@xs4all.nl (Richard Bos) - 2015-11-10 15:50 +0000
Re: Program to output initials of a name Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-27 14:13 +0000
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-27 14:15 +0000
Re: Program to output initials of a name Keith Thompson <kst-u@mib.org> - 2015-10-27 08:59 -0700
Re: Program to output initials of a name Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-27 21:34 +0000
Re: Program to output initials of a name James Kuyper <jameskuyper@verizon.net> - 2015-10-27 12:09 -0400
Re: Program to output initials of a name Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-27 20:03 +0000
Re: Program to output initials of a name James Kuyper <jameskuyper@verizon.net> - 2015-10-27 19:36 -0400
Re: Program to output initials of a name David Brown <david.brown@hesbynett.no> - 2015-10-28 09:06 +0100
Re: Program to output initials of a name Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-28 12:28 +0000
Re: Program to output initials of a name Geoff <geoff@invalid.invalid> - 2015-10-26 10:15 -0700
Re: Program to output initials of a name Ian Collins <ian-news@hotmail.com> - 2015-10-27 07:34 +1300
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-26 18:40 +0000
Re: Program to output initials of a name Bartc <bc@freeuk.com> - 2015-10-26 19:00 +0000
Re: Program to output initials of a name Ian Collins <ian-news@hotmail.com> - 2015-10-27 08:53 +1300
Re: Program to output initials of a name Bartc <bc@freeuk.com> - 2015-10-26 20:41 +0000
Re: Program to output initials of a name Ian Collins <ian-news@hotmail.com> - 2015-10-27 10:24 +1300
Re: Program to output initials of a name Keith Thompson <kst-u@mib.org> - 2015-10-26 16:06 -0700
Re: Program to output initials of a name Ian Collins <ian-news@hotmail.com> - 2015-10-27 13:16 +1300
Re: Program to output initials of a name Keith Thompson <kst-u@mib.org> - 2015-10-27 08:46 -0700
Re: Program to output initials of a name Ian Collins <ian-news@hotmail.com> - 2015-10-28 07:25 +1300
Re: Program to output initials of a name raltbos@xs4all.nl (Richard Bos) - 2015-11-10 15:52 +0000
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-27 02:15 +0000
Re: Program to output initials of a name Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-26 19:28 -0700
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-27 02:39 +0000
Re: Program to output initials of a name Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-27 02:59 -0700
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-27 10:24 +0000
Re: Program to output initials of a name Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-27 03:57 -0700
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-27 11:09 +0000
Re: Program to output initials of a name Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-27 11:23 +0000
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-27 11:28 +0000
Re: Program to output initials of a name Bartc <bc@freeuk.com> - 2015-10-27 11:37 +0000
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-27 11:46 +0000
Re: Program to output initials of a name Bartc <bc@freeuk.com> - 2015-10-27 11:50 +0000
Re: Program to output initials of a name supercat@casperkitty.com - 2015-10-27 08:44 -0700
Re: Program to output initials of a name Bartc <bc@freeuk.com> - 2015-10-27 11:19 +0000
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-27 11:25 +0000
Re: Program to output initials of a name Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-28 14:24 +0000
Re: Program to output initials of a name James Kuyper <jameskuyper@verizon.net> - 2015-10-26 14:00 -0400
Re: Program to output initials of a name Ian Collins <ian-news@hotmail.com> - 2015-10-27 11:00 +1300
Re: Program to output initials of a name Lowell Gilbert <lgusenet@be-well.ilk.org> - 2015-10-27 15:39 -0400
Re: Program to output initials of a name Keith Thompson <kst-u@mib.org> - 2015-10-26 10:17 -0700
Re: Program to output initials of a name Alla _ <modelling.data@gmail.com> - 2015-10-26 10:28 -0700
Re: Program to output initials of a name Bartc <bc@freeuk.com> - 2015-10-26 10:43 +0000
Re: Program to output initials of a name Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-26 03:52 -0700
Re: Program to output initials of a name Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-27 13:11 +0000
Re: Program to output initials of a name David Brown <david.brown@hesbynett.no> - 2015-10-27 15:14 +0100
[OT] family naming conventions James Kuyper <jameskuyper@verizon.net> - 2015-10-27 12:01 -0400
Re: [OT] family naming conventions Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2015-10-27 13:17 -0600
Re: [OT] family naming conventions Siri Cruz <chine.bleu@yahoo.com> - 2015-10-27 13:55 -0700
Re: [OT] family naming conventions Robert Wessel <robertwessel2@yahoo.com> - 2015-10-27 17:59 -0500
Re: [OT] family naming conventions raltbos@xs4all.nl (Richard Bos) - 2015-11-10 15:56 +0000
Re: [OT] family naming conventions James Kuyper <jameskuyper@verizon.net> - 2015-11-10 11:41 -0500
Re: [OT] family naming conventions raltbos@xs4all.nl (Richard Bos) - 2015-11-10 19:00 +0000
Re: [OT] family naming conventions James Kuyper <jameskuyper@verizon.net> - 2015-11-10 14:11 -0500
Re: [OT] family naming conventions raltbos@xs4all.nl (Richard Bos) - 2015-11-10 21:19 +0000
Re: [OT] family naming conventions Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-11-10 13:32 -0800
Re: [OT] family naming conventions raltbos@xs4all.nl (Richard Bos) - 2015-11-13 21:38 +0000
Re: [OT] family naming conventions Udyant Wig <udyantw@gmail.com> - 2015-11-11 15:47 +0530
Re: [OT] family naming conventions raltbos@xs4all.nl (Richard Bos) - 2015-11-13 21:36 +0000
Re: Program to output initials of a name Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-27 08:50 -0700
Re: Program to output initials of a name Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-27 16:23 +0000
Re: Program to output initials of a name Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-27 10:06 -0700
Re: Program to output initials of a name Alla _ <modelling.data@gmail.com> - 2015-10-26 05:40 -0700
Re: Program to output initials of a name Udyant Wig <udyantw@gmail.com> - 2015-10-26 16:20 +0530
Re: Program to output initials of a name Bartc <bc@freeuk.com> - 2015-10-26 10:55 +0000
Re: Program to output initials of a name Keith Thompson <kst-u@mib.org> - 2015-10-26 10:20 -0700
Re: Program to output initials of a name Bartc <bc@freeuk.com> - 2015-10-26 17:36 +0000
Re: Program to output initials of a name Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-28 16:54 -0700
Re: Program to output initials of a name Bartc <bc@freeuk.com> - 2015-10-29 00:50 +0000
Re: Program to output initials of a name Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-30 08:18 -0700
Re: Program to output initials of a name Barry Schwarz <schwarzb@dqel.com> - 2015-10-26 06:15 -0700
Re: Program to output initials of a name Alla _ <modelling.data@gmail.com> - 2015-10-26 09:42 -0700
Re: Program to output initials of a name Keith Thompson <kst-u@mib.org> - 2015-10-26 11:20 -0700
Re: Program to output initials of a name Alla _ <modelling.data@gmail.com> - 2015-10-26 09:44 -0700
Re: Program to output initials of a name Keith Thompson <kst-u@mib.org> - 2015-10-26 11:21 -0700
Re: Program to output initials of a name Alla _ <modelling.data@gmail.com> - 2015-10-26 09:47 -0700
Re: Program to output initials of a name Alla _ <modelling.data@gmail.com> - 2015-10-26 10:47 -0700
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-26 18:20 +0000
Re: Program to output initials of a name Alla _ <modelling.data@gmail.com> - 2015-10-26 11:56 -0700
Re: Program to output initials of a name Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-26 19:24 +0000
Re: Program to output initials of a name Alla _ <modelling.data@gmail.com> - 2015-10-26 12:01 -0700
Re: Program to output initials of a name Richard Heathfield <rjh@cpax.org.uk> - 2015-10-26 17:48 +0000
Re: Program to output initials of a name Keith Thompson <kst-u@mib.org> - 2015-10-26 10:43 -0700
Page 1 of 6 [1] 2 3 4 5 6 Next page →
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-10-26 03:09 -0700 |
| Subject | Program to output initials of a name |
| Message-ID | <3cd7df30-e7bc-4943-9762-f0f0a17fb3cf@googlegroups.com> |
Hello!
Below I am posting a first version of a program
that should output initials of a user's name
in uppercase letters, without spaces.
Please, do me a favor and take a look at this
first version, which is a truncated version of
the initial program I wrote.
The initial version doesn't work, therefore
to find what is wrong, I have broken the
program into few simpler versions.
I would be grateful if, for now, you do not add additional
suggestions on how to do this task, and help me
only within this first, the simplest, version without
adding more complicated features into it.
If I understand my mistakes in this one, I will try to
figure out my mistakes in fuller version, and post questions
later.
I am testing it without 'prompt-the-user' feature.
I read this program the following way:
- the name array is Alla;
- length of the name array is 4;
- print the first letter in uppercase (as
it if already in the upper case, print as
it is);
- for loop starts from the letter 'l' (i = 1)
and scans the whole name to see if there are
any spaces between letters;
- there are no spaces, hence only one letter
should be printed out;
- in case there were spaces, after printing
the first letter (printed in any case), the program
prints out every letter after the space, i.e. name[i+1].
Why does the program print 'ALA' as the outcome, if
there are no spaces in the word Alla?
/**
* Program to print initials of the name
**/
#include <stdio.h>
#include <string.h>
void toupper_initials(char user_name[]);
int main(void)
{
char name[] = "Alla";
toupper_initials(name);
return 0;
}
/** Function to print initials in uppercase letters
without spaces
**/
void toupper_initials(char user_name[])
{
char initials[80];
char space = ' ';
int len = strlen(user_name);
int i;
printf("%c", toupper(user_name[0]));
for (i = 1; i < len; i++) /** also can be while(user_name[i] != '\0') **/
{
/** if the user has entered several names (divided by spaces),
then convert to upper case each letter after the space in the
user_name array; if the letter is in upper case, toupper prints
the letter as it is
**/
if (user_name[i] = space)
{
initials[i] = toupper(user_name[i + 1]);
printf("%c", initials[i]);
}
}
/** if there are no spaces between letters, the for loop terminates
after scanning the whole string, and should produce no outcome;
thus the program prints out only the first letter in upper case **/
printf("\n");
}
Thank you!
[toc] | [next] | [standalone]
| From | Malcolm McLean <malcolm.mclean5@btinternet.com> |
|---|---|
| Date | 2015-10-26 03:22 -0700 |
| Message-ID | <f6c5437f-0bbb-4b9b-a725-dfc54f6ca918@googlegroups.com> |
| In reply to | #73834 |
On Monday, October 26, 2015 at 10:10:05 AM UTC, Alla _ wrote:
> Hello!
>
> Below I am posting a first version of a program
> that should output initials of a user's name
> in uppercase letters, without spaces.
>
> Please, do me a favor and take a look at this
> first version, which is a truncated version of
> the initial program I wrote.
>
> The initial version doesn't work, therefore
> to find what is wrong, I have broken the
> program into few simpler versions.
>
> I would be grateful if, for now, you do not add additional
> suggestions on how to do this task, and help me
> only within this first, the simplest, version without
> adding more complicated features into it.
>
> If I understand my mistakes in this one, I will try to
> figure out my mistakes in fuller version, and post questions
> later.
>
> I am testing it without 'prompt-the-user' feature.
>
> I read this program the following way:
>
> - the name array is Alla;
>
> - length of the name array is 4;
>
> - print the first letter in uppercase (as
> it if already in the upper case, print as
> it is);
>
> - for loop starts from the letter 'l' (i = 1)
> and scans the whole name to see if there are
> any spaces between letters;
>
> - there are no spaces, hence only one letter
> should be printed out;
>
> - in case there were spaces, after printing
> the first letter (printed in any case), the program
> prints out every letter after the space, i.e. name[i+1].
>
> Why does the program print 'ALA' as the outcome, if
> there are no spaces in the word Alla?
>
>
> /**
> * Program to print initials of the name
> **/
>
> #include <stdio.h>
> #include <string.h>
>
> void toupper_initials(char user_name[]);
>
> int main(void)
> {
> char name[] = "Alla";
>
> toupper_initials(name);
>
> return 0;
> }
>
> /** Function to print initials in uppercase letters
> without spaces
> **/
>
> void toupper_initials(char user_name[])
> {
> char initials[80];
> char space = ' ';
> int len = strlen(user_name);
> int i;
>
> printf("%c", toupper(user_name[0]));
>
> for (i = 1; i < len; i++) /** also can be while(user_name[i] != '\0') **/
> {
>
> /** if the user has entered several names (divided by spaces),
> then convert to upper case each letter after the space in the
> user_name array; if the letter is in upper case, toupper prints
> the letter as it is
> **/
> if (user_name[i] = space)
> {
> initials[i] = toupper(user_name[i + 1]);
>
> printf("%c", initials[i]);
> }
> }
> /** if there are no spaces between letters, the for loop terminates
> after scanning the whole string, and should produce no outcome;
> thus the program prints out only the first letter in upper case **/
>
> printf("\n");
> }
>
> Thank you!
this is a common error.
if (user_name[i] = space)
it should be ==.
But the program is not structured in a very logical way.
I'd rewrite the function as
int get_initials(char *ret, const char *user_name).
The write main like this
int main(void)
{
char initials[80]; // You'll never have more than 80 initials
char *name = "Alla the C programmer";
get_initials(initials, name);
printf("Name : \"%s\"", name);
printf("Initials: %s\n", initials);
}
Now we've got a test framework. You just change the name variable to run test
after test until you're happy that the function always works.
In a second version, of course you'll input the name from the user, and it would be wise
to allocate an "initials" buffer big enough to hold the entire name, for safety.
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-10-26 05:32 -0700 |
| Message-ID | <725f2616-1678-405d-b97c-640de4a333f1@googlegroups.com> |
| In reply to | #73837 |
On Monday, October 26, 2015 at 2:22:17 PM UTC+4, Malcolm McLean wrote:
> On Monday, October 26, 2015 at 10:10:05 AM UTC, Alla _ wrote:
> > Hello!
> >
> > Below I am posting a first version of a program
> > that should output initials of a user's name
> > in uppercase letters, without spaces.
> >
> > Please, do me a favor and take a look at this
> > first version, which is a truncated version of
> > the initial program I wrote.
> >
> > The initial version doesn't work, therefore
> > to find what is wrong, I have broken the
> > program into few simpler versions.
> >
> > I would be grateful if, for now, you do not add additional
> > suggestions on how to do this task, and help me
> > only within this first, the simplest, version without
> > adding more complicated features into it.
> >
> > If I understand my mistakes in this one, I will try to
> > figure out my mistakes in fuller version, and post questions
> > later.
> >
> > I am testing it without 'prompt-the-user' feature.
> >
> > I read this program the following way:
> >
> > - the name array is Alla;
> >
> > - length of the name array is 4;
> >
> > - print the first letter in uppercase (as
> > it if already in the upper case, print as
> > it is);
> >
> > - for loop starts from the letter 'l' (i = 1)
> > and scans the whole name to see if there are
> > any spaces between letters;
> >
> > - there are no spaces, hence only one letter
> > should be printed out;
> >
> > - in case there were spaces, after printing
> > the first letter (printed in any case), the program
> > prints out every letter after the space, i.e. name[i+1].
> >
> > Why does the program print 'ALA' as the outcome, if
> > there are no spaces in the word Alla?
> >
> >
> > /**
> > * Program to print initials of the name
> > **/
> >
> > #include <stdio.h>
> > #include <string.h>
> >
> > void toupper_initials(char user_name[]);
> >
> > int main(void)
> > {
> > char name[] = "Alla";
> >
> > toupper_initials(name);
> >
> > return 0;
> > }
> >
> > /** Function to print initials in uppercase letters
> > without spaces
> > **/
> >
> > void toupper_initials(char user_name[])
> > {
> > char initials[80];
> > char space = ' ';
> > int len = strlen(user_name);
> > int i;
> >
> > printf("%c", toupper(user_name[0]));
> >
> > for (i = 1; i < len; i++) /** also can be while(user_name[i] != '\0') **/
> > {
> >
> > /** if the user has entered several names (divided by spaces),
> > then convert to upper case each letter after the space in the
> > user_name array; if the letter is in upper case, toupper prints
> > the letter as it is
> > **/
> > if (user_name[i] = space)
> > {
> > initials[i] = toupper(user_name[i + 1]);
> >
> > printf("%c", initials[i]);
> > }
> > }
> > /** if there are no spaces between letters, the for loop terminates
> > after scanning the whole string, and should produce no outcome;
> > thus the program prints out only the first letter in upper case **/
> >
> > printf("\n");
> > }
> >
> > Thank you!
>
> this is a common error.
>
> if (user_name[i] = space)
>
> it should be ==.
>
> But the program is not structured in a very logical way.
>
> I'd rewrite the function as
>
> int get_initials(char *ret, const char *user_name).
>
> The write main like this
>
> int main(void)
> {
> char initials[80]; // You'll never have more than 80 initials
> char *name = "Alla the C programmer";
>
> get_initials(initials, name);
> printf("Name : \"%s\"", name);
> printf("Initials: %s\n", initials);
> }
>
> Now we've got a test framework. You just change the name variable to run test
> after test until you're happy that the function always works.
> In a second version, of course you'll input the name from the user, and it would be wise
> to allocate an "initials" buffer big enough to hold the entire name, for safety.
Thank you! I will try this too.
My second version is more "rich" )
[toc] | [prev] | [next] | [standalone]
| From | Barry Schwarz <schwarzb@dqel.com> |
|---|---|
| Date | 2015-10-26 14:34 -0700 |
| Message-ID | <8v6t2b95qh01b71n06bbundt669gg09bo4@4ax.com> |
| In reply to | #73847 |
On Mon, 26 Oct 2015 05:32:59 -0700 (PDT), Alla _ <modelling.data@gmail.com> wrote: <snip 130+ lines of mostly obsolete discussion> > >Thank you! I will try this too. >My second version is more "rich" ) Please don't quote hundreds of lines just to say thank you. -- Remove del for email
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2015-10-26 10:38 +0000 |
| Message-ID | <n0kvmm$abk$1@dont-email.me> |
| In reply to | #73834 |
On 26/10/15 10:09, Alla _ wrote:
> Hello!
>
> Below I am posting a first version of a program
> that should output initials of a user's name
> in uppercase letters, without spaces.
Okay.
> Please, do me a favor and take a look at this
> first version, which is a truncated version of
> the initial program I wrote.
Okay. First question: does it compile? (Answer: well, yes, but I got
quite a few warning messages, and some of them matter.)
<snip>
> I read this program the following way:
>
> - the name array is Alla;
>
> - length of the name array is 4;
char name[] = "Alla";
When you define and initialise a char array in this manner (with empty
brackets), the compiler reserves enough space for the string AND a null
terminating character. It is as if you had written:
char name[] = { 'A', 'l', 'l', 'a', '\0' };
Count them. How many elements?
The length of the /string/ is 4, which is probably what you were
thinking of.
>
> - print the first letter in uppercase (as
> it if already in the upper case, print as
> it is);
Well, let's look at main() first:
int main(void)
{
char name[] = "Alla";
toupper_initials(name);
return 0;
}
Okay, that's good - you've learned that main() is for high-level
control, and that the fine detail of the program belongs in other
functions. Moving on:
void toupper_initials(char user_name[])
{
char initials[80];
char space = ' ';
int len = strlen(user_name);
Well, strictly, strlen returns a size_t. Never mind. The int will do,
for now. (Begin a "to-do list" of things you need to learn *LATER*. The
size_t type is one of those things. Keep the list up to date, but don't
try to learn any of the topics on it until you're getting the easy stuff
right.)
int i;
printf("%c", toupper(user_name[0]));
What if the input had been, say, " Alla"? Users do that kind of thing,
I'm afraid. Don't worry about it - you have more important things to
worry about right now - but it's something to add to your to-do list -
"how to deal with awkward users"!
> - for loop starts from the letter 'l' (i = 1)
It does.
> and scans the whole name to see if there are
> any spaces between letters;
Does it? Let's have a look:
if (user_name[i] = space)
Here's your first serious bug. Can you see what's wrong?
You would do well to spot this yourself, but if you're really stuck,
scroll down past all the "spoiler space".
Answer follows 100 spoiler warnings.
Answer follows 99 spoiler warnings.
Answer follows 98 spoiler warnings.
Answer follows 97 spoiler warnings.
Answer follows 96 spoiler warnings.
Answer follows 95 spoiler warnings.
Answer follows 94 spoiler warnings.
Answer follows 93 spoiler warnings.
Answer follows 92 spoiler warnings.
Answer follows 91 spoiler warnings.
Answer follows 90 spoiler warnings.
Answer follows 89 spoiler warnings.
Answer follows 88 spoiler warnings.
Answer follows 87 spoiler warnings.
Answer follows 86 spoiler warnings.
Answer follows 85 spoiler warnings.
Answer follows 84 spoiler warnings.
Answer follows 83 spoiler warnings.
Answer follows 82 spoiler warnings.
Answer follows 81 spoiler warnings.
Answer follows 80 spoiler warnings.
Answer follows 79 spoiler warnings.
Answer follows 78 spoiler warnings.
Answer follows 77 spoiler warnings.
Answer follows 76 spoiler warnings.
Answer follows 75 spoiler warnings.
Answer follows 74 spoiler warnings.
Answer follows 73 spoiler warnings.
Answer follows 72 spoiler warnings.
Answer follows 71 spoiler warnings.
Answer follows 70 spoiler warnings.
Answer follows 69 spoiler warnings.
Answer follows 68 spoiler warnings.
Answer follows 67 spoiler warnings.
Answer follows 66 spoiler warnings.
Answer follows 65 spoiler warnings.
Answer follows 64 spoiler warnings.
Answer follows 63 spoiler warnings.
Answer follows 62 spoiler warnings.
Answer follows 61 spoiler warnings.
Answer follows 60 spoiler warnings.
Answer follows 59 spoiler warnings.
Answer follows 58 spoiler warnings.
Answer follows 57 spoiler warnings.
Answer follows 56 spoiler warnings.
Answer follows 55 spoiler warnings.
Answer follows 54 spoiler warnings.
Answer follows 53 spoiler warnings.
Answer follows 52 spoiler warnings.
Answer follows 51 spoiler warnings.
Answer follows 50 spoiler warnings.
Answer follows 49 spoiler warnings.
Answer follows 48 spoiler warnings.
Answer follows 47 spoiler warnings.
Answer follows 46 spoiler warnings.
Answer follows 45 spoiler warnings.
Answer follows 44 spoiler warnings.
Answer follows 43 spoiler warnings.
Answer follows 42 spoiler warnings.
Answer follows 41 spoiler warnings.
Answer follows 40 spoiler warnings.
Answer follows 39 spoiler warnings.
Answer follows 38 spoiler warnings.
Answer follows 37 spoiler warnings.
Answer follows 36 spoiler warnings.
Answer follows 35 spoiler warnings.
Answer follows 34 spoiler warnings.
Answer follows 33 spoiler warnings.
Answer follows 32 spoiler warnings.
Answer follows 31 spoiler warnings.
Answer follows 30 spoiler warnings.
Answer follows 29 spoiler warnings.
Answer follows 28 spoiler warnings.
Answer follows 27 spoiler warnings.
Answer follows 26 spoiler warnings.
Answer follows 25 spoiler warnings.
Answer follows 24 spoiler warnings.
Answer follows 23 spoiler warnings.
Answer follows 22 spoiler warnings.
Answer follows 21 spoiler warnings.
Answer follows 20 spoiler warnings.
Answer follows 19 spoiler warnings.
Answer follows 18 spoiler warnings.
Answer follows 17 spoiler warnings.
Answer follows 16 spoiler warnings.
Answer follows 15 spoiler warnings.
Answer follows 14 spoiler warnings.
Answer follows 13 spoiler warnings.
Answer follows 12 spoiler warnings.
Answer follows 11 spoiler warnings.
Answer follows 10 spoiler warnings.
Answer follows 9 spoiler warnings.
Answer follows 8 spoiler warnings.
Answer follows 7 spoiler warnings.
Answer follows 6 spoiler warnings.
Answer follows 5 spoiler warnings.
Answer follows 4 spoiler warnings.
Answer follows 3 spoiler warnings.
Answer follows 2 spoiler warnings.
Answer follows 1 spoiler warning.
Answer follows 0 spoiler warnings.
= is the ASSIGNMENT operator. You wanted ==, the COMPARISON operator.
--
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-10-26 05:37 -0700 |
| Message-ID | <6b2fd7b2-0f00-40e8-80c0-b620cd15d0fe@googlegroups.com> |
| In reply to | #73839 |
On Monday, October 26, 2015 at 2:38:25 PM UTC+4, Richard Heathfield wrote:
> On 26/10/15 10:09, Alla _ wrote:
> > Hello!
> >
> > Below I am posting a first version of a program
> > that should output initials of a user's name
> > in uppercase letters, without spaces.
>
> Okay.
>
> > Please, do me a favor and take a look at this
> > first version, which is a truncated version of
> > the initial program I wrote.
>
> Okay. First question: does it compile? (Answer: well, yes, but I got
> quite a few warning messages, and some of them matter.)
>
> <snip>
>
> > I read this program the following way:
> >
> > - the name array is Alla;
> >
> > - length of the name array is 4;
>
> char name[] = "Alla";
>
> When you define and initialise a char array in this manner (with empty
> brackets), the compiler reserves enough space for the string AND a null
> terminating character. It is as if you had written:
>
> char name[] = { 'A', 'l', 'l', 'a', '\0' };
>
> Count them. How many elements?
>
> The length of the /string/ is 4, which is probably what you were
> thinking of.
>
> >
> > - print the first letter in uppercase (as
> > it if already in the upper case, print as
> > it is);
>
> Well, let's look at main() first:
>
> int main(void)
> {
> char name[] = "Alla";
>
> toupper_initials(name);
>
> return 0;
> }
>
> Okay, that's good - you've learned that main() is for high-level
> control, and that the fine detail of the program belongs in other
> functions. Moving on:
>
> void toupper_initials(char user_name[])
> {
> char initials[80];
> char space = ' ';
> int len = strlen(user_name);
>
> Well, strictly, strlen returns a size_t. Never mind. The int will do,
> for now. (Begin a "to-do list" of things you need to learn *LATER*. The
> size_t type is one of those things. Keep the list up to date, but don't
> try to learn any of the topics on it until you're getting the easy stuff
> right.)
>
> int i;
>
> printf("%c", toupper(user_name[0]));
>
> What if the input had been, say, " Alla"? Users do that kind of thing,
> I'm afraid. Don't worry about it - you have more important things to
> worry about right now - but it's something to add to your to-do list -
> "how to deal with awkward users"!
>
> > - for loop starts from the letter 'l' (i = 1)
>
> It does.
>
> > and scans the whole name to see if there are
> > any spaces between letters;
>
> Does it? Let's have a look:
>
> if (user_name[i] = space)
>
> Here's your first serious bug. Can you see what's wrong?
>
> You would do well to spot this yourself, but if you're really stuck,
> scroll down past all the "spoiler space".
>
>
> Answer follows 100 spoiler warnings.
>
> Answer follows 99 spoiler warnings.
>
> Answer follows 98 spoiler warnings.
>
> Answer follows 97 spoiler warnings.
>
> Answer follows 96 spoiler warnings.
>
> Answer follows 95 spoiler warnings.
>
> Answer follows 94 spoiler warnings.
>
> Answer follows 93 spoiler warnings.
>
> Answer follows 92 spoiler warnings.
>
> Answer follows 91 spoiler warnings.
>
> Answer follows 90 spoiler warnings.
>
> Answer follows 89 spoiler warnings.
>
> Answer follows 88 spoiler warnings.
>
> Answer follows 87 spoiler warnings.
>
> Answer follows 86 spoiler warnings.
>
> Answer follows 85 spoiler warnings.
>
> Answer follows 84 spoiler warnings.
>
> Answer follows 83 spoiler warnings.
>
> Answer follows 82 spoiler warnings.
>
> Answer follows 81 spoiler warnings.
>
> Answer follows 80 spoiler warnings.
>
> Answer follows 79 spoiler warnings.
>
> Answer follows 78 spoiler warnings.
>
> Answer follows 77 spoiler warnings.
>
> Answer follows 76 spoiler warnings.
>
> Answer follows 75 spoiler warnings.
>
> Answer follows 74 spoiler warnings.
>
> Answer follows 73 spoiler warnings.
>
> Answer follows 72 spoiler warnings.
>
> Answer follows 71 spoiler warnings.
>
> Answer follows 70 spoiler warnings.
>
> Answer follows 69 spoiler warnings.
>
> Answer follows 68 spoiler warnings.
>
> Answer follows 67 spoiler warnings.
>
> Answer follows 66 spoiler warnings.
>
> Answer follows 65 spoiler warnings.
>
> Answer follows 64 spoiler warnings.
>
> Answer follows 63 spoiler warnings.
>
> Answer follows 62 spoiler warnings.
>
> Answer follows 61 spoiler warnings.
>
> Answer follows 60 spoiler warnings.
>
> Answer follows 59 spoiler warnings.
>
> Answer follows 58 spoiler warnings.
>
> Answer follows 57 spoiler warnings.
>
> Answer follows 56 spoiler warnings.
>
> Answer follows 55 spoiler warnings.
>
> Answer follows 54 spoiler warnings.
>
> Answer follows 53 spoiler warnings.
>
> Answer follows 52 spoiler warnings.
>
> Answer follows 51 spoiler warnings.
>
> Answer follows 50 spoiler warnings.
>
> Answer follows 49 spoiler warnings.
>
> Answer follows 48 spoiler warnings.
>
> Answer follows 47 spoiler warnings.
>
> Answer follows 46 spoiler warnings.
>
> Answer follows 45 spoiler warnings.
>
> Answer follows 44 spoiler warnings.
>
> Answer follows 43 spoiler warnings.
>
> Answer follows 42 spoiler warnings.
>
> Answer follows 41 spoiler warnings.
>
> Answer follows 40 spoiler warnings.
>
> Answer follows 39 spoiler warnings.
>
> Answer follows 38 spoiler warnings.
>
> Answer follows 37 spoiler warnings.
>
> Answer follows 36 spoiler warnings.
>
> Answer follows 35 spoiler warnings.
>
> Answer follows 34 spoiler warnings.
>
> Answer follows 33 spoiler warnings.
>
> Answer follows 32 spoiler warnings.
>
> Answer follows 31 spoiler warnings.
>
> Answer follows 30 spoiler warnings.
>
> Answer follows 29 spoiler warnings.
>
> Answer follows 28 spoiler warnings.
>
> Answer follows 27 spoiler warnings.
>
> Answer follows 26 spoiler warnings.
>
> Answer follows 25 spoiler warnings.
>
> Answer follows 24 spoiler warnings.
>
> Answer follows 23 spoiler warnings.
>
> Answer follows 22 spoiler warnings.
>
> Answer follows 21 spoiler warnings.
>
> Answer follows 20 spoiler warnings.
>
> Answer follows 19 spoiler warnings.
>
> Answer follows 18 spoiler warnings.
>
> Answer follows 17 spoiler warnings.
>
> Answer follows 16 spoiler warnings.
>
> Answer follows 15 spoiler warnings.
>
> Answer follows 14 spoiler warnings.
>
> Answer follows 13 spoiler warnings.
>
> Answer follows 12 spoiler warnings.
>
> Answer follows 11 spoiler warnings.
>
> Answer follows 10 spoiler warnings.
>
> Answer follows 9 spoiler warnings.
>
> Answer follows 8 spoiler warnings.
>
> Answer follows 7 spoiler warnings.
>
> Answer follows 6 spoiler warnings.
>
> Answer follows 5 spoiler warnings.
>
> Answer follows 4 spoiler warnings.
>
> Answer follows 3 spoiler warnings.
>
> Answer follows 2 spoiler warnings.
>
> Answer follows 1 spoiler warning.
>
> Answer follows 0 spoiler warnings.
>
> = is the ASSIGNMENT operator. You wanted ==, the COMPARISON operator.
>
> --
> Richard Heathfield
> Email: rjh at cpax dot org dot uk
> "Usenet is a strange place" - dmr 29 July 1999
> Sig line 4 vacant - apply within
Oh, no. Yet again. Same old mistake. I've
made it many times, talked to myself about it,
thought it's fixed, and ... voila - only one =,
instead of ==.
Thank you!
What's interesting, my compiler didn't even
bother itself to warn me this time, and
compiled the program.
In one of my previous posts I had a suggestion to use
size_t, and I have learned about it, have written a few
notes in my 'C vade macum' )
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2015-10-26 13:53 +0000 |
| Message-ID | <87egghlorx.fsf@bsb.me.uk> |
| In reply to | #73848 |
Alla _ <modelling.data@gmail.com> writes: > On Monday, October 26, 2015 at 2:38:25 PM UTC+4, Richard Heathfield wrote: <snip> >> = is the ASSIGNMENT operator. You wanted ==, the COMPARISON operator. <snip> > Oh, no. Yet again. Same old mistake. I've > made it many times, talked to myself about it, > thought it's fixed, and ... voila - only one =, > instead of ==. > > Thank you! > > What's interesting, my compiler didn't even > bother itself to warn me this time, and > compiled the program. What compiler and what options? When you are learning, it's handy to use lots of warning options. My default settings for gcc warn about the "assignment used as truth value" in your program. <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | Alla _ <modelling.data@gmail.com> |
|---|---|
| Date | 2015-10-26 07:33 -0700 |
| Message-ID | <c7db8997-9575-4c07-9054-7255a299e0e4@googlegroups.com> |
| In reply to | #73855 |
On Monday, October 26, 2015 at 5:53:30 PM UTC+4, Ben Bacarisse wrote: > Alla _ <modelling.data@gmail.com> writes: > > > On Monday, October 26, 2015 at 2:38:25 PM UTC+4, Richard Heathfield wrote: > <snip> > >> = is the ASSIGNMENT operator. You wanted ==, the COMPARISON operator. > <snip> > > Oh, no. Yet again. Same old mistake. I've > > made it many times, talked to myself about it, > > thought it's fixed, and ... voila - only one =, > > instead of ==. > > > > Thank you! > > > > What's interesting, my compiler didn't even > > bother itself to warn me this time, and > > compiled the program. > > What compiler and what options? When you are learning, it's handy to > use lots of warning options. My default settings for gcc warn about the > "assignment used as truth value" in your program. > > <snip> > -- > Ben. Here is the information on compiler i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2015-10-26 15:21 +0000 |
| Message-ID | <n0lgah$d1q$1@dont-email.me> |
| In reply to | #73857 |
On 26/10/15 14:33, Alla _ wrote: <snip> > Here is the information on compiler > > i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00) Okay, if that's gcc, which it looks very much like it is, then you could do worse than use the following options BUT before I show them to you, you obviously realise that any suggestion here provokes a veritable storm of objections. Be prepared for that, and consider very closely any advice on specific warning settings offered to you by, for example, Eric Sosman, Keith Thompson, Ian Collins, Richard Bos, Ben Bacarisse, and James Kuyper. I'm not suggesting that other people might not have good suggestions, but you might want to consider those half-dozen names as being 'trumps', so to speak. If a majority of them share the same opinion (positive or negative) about a compiler warning, it's probably worth going with that majority. So here's a decent set to get you started: -W -Wall -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes -Wno-missing-field-initializers -Wmissing-declarations -Winline -Wundef -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | Bartc <bc@freeuk.com> |
|---|---|
| Date | 2015-10-26 16:26 +0000 |
| Message-ID | <n0lk3r$ur6$1@dont-email.me> |
| In reply to | #73862 |
On 26/10/2015 15:21, Richard Heathfield wrote: > On 26/10/15 14:33, Alla _ wrote: > > <snip> > >> Here is the information on compiler >> >> i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. >> build 5658) (LLVM build 2336.11.00) > So here's a decent set to get you started: > > -W -Wall -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith > -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes > -Wno-missing-field-initializers -Wmissing-declarations -Winline -Wundef > -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings And a very intimidating set of options that is enough to put anyone off for life. Next problem is how to arrange for that lot to be given to the compiler automatically, without having to type them in every time. We then find ourselves drifting away from learning the language, to grappling with tools. (BTW Clang, the Windows version anyway, will warn against using assignments as conditional expressions. I was under the impression the above version of 'gcc' is really clang, but presumably that warning option is not automatic. Perhaps to keep it 'compatible'.) -- Bartc
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2015-10-26 16:41 +0000 |
| Message-ID | <n0lkve$32j$1@dont-email.me> |
| In reply to | #73866 |
On 26/10/15 16:26, Bartc wrote: > On 26/10/2015 15:21, Richard Heathfield wrote: >> On 26/10/15 14:33, Alla _ wrote: >> >> <snip> >> >>> Here is the information on compiler >>> >>> i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. >>> build 5658) (LLVM build 2336.11.00) > >> So here's a decent set to get you started: >> >> -W -Wall -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith >> -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes >> -Wno-missing-field-initializers -Wmissing-declarations -Winline -Wundef >> -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings > > And a very intimidating set of options that is enough to put anyone off > for life. What I would find intimidating is not being able to find problems in my code because the compiler didn't tell me about them. > Next problem is how to arrange for that lot to be given to the compiler > automatically, without having to type them in every time. Do you seriously think that's a problem? You're a C programmer, right? How hard could it be to write a C program to generate the makefile for you? Mine is about 130 lines of bog-standard ordinary C. > We then find ourselves drifting away from learning the language, to > grappling with tools. Grappling? You make too much of a trifle. -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | Geoff <geoff@invalid.invalid> |
|---|---|
| Date | 2015-10-26 10:27 -0700 |
| Message-ID | <60os2blrrh66pmkta1rp199n2odmsklhuc@4ax.com> |
| In reply to | #73868 |
On Mon, 26 Oct 2015 16:41:19 +0000, Richard Heathfield <rjh@cpax.org.uk> wrote: >On 26/10/15 16:26, Bartc wrote: >> On 26/10/2015 15:21, Richard Heathfield wrote: >>> On 26/10/15 14:33, Alla _ wrote: >>> >>> <snip> >>> >>>> Here is the information on compiler >>>> >>>> i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. >>>> build 5658) (LLVM build 2336.11.00) >> >>> So here's a decent set to get you started: >>> >>> -W -Wall -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith >>> -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes >>> -Wno-missing-field-initializers -Wmissing-declarations -Winline -Wundef >>> -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings >> >> And a very intimidating set of options that is enough to put anyone off >> for life. > >What I would find intimidating is not being able to find problems in my >code because the compiler didn't tell me about them. > >> Next problem is how to arrange for that lot to be given to the compiler >> automatically, without having to type them in every time. > >Do you seriously think that's a problem? You're a C programmer, right? >How hard could it be to write a C program to generate the makefile for >you? Mine is about 130 lines of bog-standard ordinary C. > >> We then find ourselves drifting away from learning the language, to >> grappling with tools. > >Grappling? You make too much of a trifle. Grappling? YES! She's working from the command line. She's trying to focus on C, the language, not make and a pile of command line switches for every iteration of her code. Yes, up-arrow might save her from most of it but she'd still have to copy-paste it somewhere to keep from making even more errors that would distract from learning C. A C program to generate a make file? See, you've grappled with it and invented or found a workaround from an insanely complex array of command line switches to save yourself the trouble of grappling with the tools. Alla_ would be well advised to install Xcode on her system that would help her master C and a modern IDE.
[toc] | [prev] | [next] | [standalone]
| From | Bartc <bc@freeuk.com> |
|---|---|
| Date | 2015-10-26 17:29 +0000 |
| Message-ID | <n0lnqe$ffu$1@dont-email.me> |
| In reply to | #73868 |
On 26/10/2015 16:41, Richard Heathfield wrote: > On 26/10/15 16:26, Bartc wrote: >> On 26/10/2015 15:21, Richard Heathfield wrote: >>> On 26/10/15 14:33, Alla _ wrote: >>> >>> <snip> >>> >>>> Here is the information on compiler >>>> >>>> i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. >>>> build 5658) (LLVM build 2336.11.00) >> >>> So here's a decent set to get you started: >>> >>> -W -Wall -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith >>> -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes >>> -Wno-missing-field-initializers -Wmissing-declarations -Winline -Wundef >>> -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings >> >> And a very intimidating set of options that is enough to put anyone off >> for life. > > What I would find intimidating is not being able to find problems in my > code because the compiler didn't tell me about them. Put yourself back in the position of using a mysterious thing called a 'compiler' for the first time. I say that those options are intimidating. As are the hundred of pointless warnings that will be generated that will likely swamp any actual problems. Such as the one generated here from a 64-bit compiler: char *s; int len; .... len = strlen(s); because you are converting from size_t down to int. (And don't say we should be obliged to use 64-bit counts for string lengths in all circumstances.) >> Next problem is how to arrange for that lot to be given to the compiler >> automatically, without having to type them in every time. > > Do you seriously think that's a problem? You're a C programmer, right? Yes I can do it (by sticking them all on a single long line in a batch file in this case). But we're talking about beginners (it might even be worse for an experience programmer new to C). > How hard could it be to write a C program to generate the makefile for > you? And then we really are learning a different language. -- Bartc
[toc] | [prev] | [next] | [standalone]
| From | raltbos@xs4all.nl (Richard Bos) |
|---|---|
| Date | 2015-11-10 15:40 +0000 |
| Message-ID | <56420f69.3245703@news.xs4all.nl> |
| In reply to | #73882 |
Bartc <bc@freeuk.com> wrote: > On 26/10/2015 16:41, Richard Heathfield wrote: > > What I would find intimidating is not being able to find problems in my > > code because the compiler didn't tell me about them. > > Put yourself back in the position of using a mysterious thing called a > 'compiler' for the first time. I say that those options are intimidating. Back when I first used a compiler, I already knew how this mysterious thing called "batch files" worked. I believe Gnunix* has something similar called "script files", though I'm also sure you'll find advocates arguing - against the very point! - that they're much superior. HTH; HAND. Richard * Complain to the GNU/HURL crowd if you must, not to me - I didn't start the pretense!
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2015-10-27 13:36 +0000 |
| Message-ID | <slrnn2uvf4.5q5.grahn+nntp@frailea.sa.invalid> |
| In reply to | #73868 |
On Mon, 2015-10-26, Richard Heathfield wrote:
> On 26/10/15 16:26, Bartc wrote:
>> On 26/10/2015 15:21, Richard Heathfield wrote:
>>> On 26/10/15 14:33, Alla _ wrote:
>>>
>>> <snip>
>>>
>>>> Here is the information on compiler
>>>>
>>>> i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc.
>>>> build 5658) (LLVM build 2336.11.00)
>>
>>> So here's a decent set to get you started:
>>>
>>> -W -Wall -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith
>>> -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes
>>> -Wno-missing-field-initializers -Wmissing-declarations -Winline -Wundef
>>> -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
>>
>> And a very intimidating set of options that is enough to put anyone off
>> for life.
>
> What I would find intimidating is not being able to find problems in my
> code because the compiler didn't tell me about them.
And it's common for newbies to ask here about errors which the
compiler could have spotted, if it had been allowed to.
You're both right. I suspect the list is unnecessarily long ... and
at the same time I miss a -std=c99 or =c89 in it. See below.
>> Next problem is how to arrange for that lot to be given to the compiler
>> automatically, without having to type them in every time.
>
> Do you seriously think that's a problem? You're a C programmer, right?
> How hard could it be to write a C program to generate the makefile for
> you? Mine is about 130 lines of bog-standard ordinary C.
Why would you want to do that when you can just write the Makefile
manually?
CFLAGS=-W -Wall -pedantic -std=c99
foo: foo.o
$(CC) $(CFLAGS) -o $@ $^
That should be all needed for a one-file program.
>> We then find ourselves drifting away from learning the language, to
>> grappling with tools.
>
> Grappling? You make too much of a trifle.
And in any case, you need to know your tools, sooner or later.
Spending a day setting up compiler, build tool, editor and version
control would be a good investment for a beginner.
/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
[toc] | [prev] | [next] | [standalone]
| From | Richard Heathfield <rjh@cpax.org.uk> |
|---|---|
| Date | 2015-10-27 13:45 +0000 |
| Message-ID | <n0nv17$pke$1@dont-email.me> |
| In reply to | #73954 |
On 27/10/15 13:36, Jorgen Grahn wrote: > On Mon, 2015-10-26, Richard Heathfield wrote: >> On 26/10/15 16:26, Bartc wrote: >>> On 26/10/2015 15:21, Richard Heathfield wrote: >>>> On 26/10/15 14:33, Alla _ wrote: >>>> >>>> <snip> >>>> >>>>> Here is the information on compiler >>>>> >>>>> i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. >>>>> build 5658) (LLVM build 2336.11.00) >>> >>>> So here's a decent set to get you started: >>>> >>>> -W -Wall -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith >>>> -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes >>>> -Wno-missing-field-initializers -Wmissing-declarations -Winline -Wundef >>>> -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings >>> >>> And a very intimidating set of options that is enough to put anyone off >>> for life. >> >> What I would find intimidating is not being able to find problems in my >> code because the compiler didn't tell me about them. > > And it's common for newbies to ask here about errors which the > compiler could have spotted, if it had been allowed to. Right. Alla has in fact done precisely that. > You're both right. I suspect the list is unnecessarily long ... and > at the same time I miss a -std=c99 or =c89 in it. See below. I left it out because I use -ansi but I suspect Alla probably needs -std=c99 (judging by her code). >>> Next problem is how to arrange for that lot to be given to the compiler >>> automatically, without having to type them in every time. >> >> Do you seriously think that's a problem? You're a C programmer, right? >> How hard could it be to write a C program to generate the makefile for >> you? Mine is about 130 lines of bog-standard ordinary C. > > Why would you want to do that when you can just write the Makefile > manually? > > CFLAGS=-W -Wall -pedantic -std=c99 > foo: foo.o > $(CC) $(CFLAGS) -o $@ $^ > > That should be all needed for a one-file program. What a lot of typing! :-) I use: $ makegen foo bar baz > Makefile and that spits out everything I need for a foo executable that links to bar and baz. >>> We then find ourselves drifting away from learning the language, to >>> grappling with tools. >> >> Grappling? You make too much of a trifle. > > And in any case, you need to know your tools, sooner or later. > Spending a day setting up compiler, build tool, editor and version > control would be a good investment for a beginner. Yup. -- Richard Heathfield Email: rjh at cpax dot org dot uk "Usenet is a strange place" - dmr 29 July 1999 Sig line 4 vacant - apply within
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2015-10-27 15:10 +0100 |
| Message-ID | <n0o0gc$veu$1@dont-email.me> |
| In reply to | #73954 |
On 27/10/15 14:36, Jorgen Grahn wrote: > On Mon, 2015-10-26, Richard Heathfield wrote: >> On 26/10/15 16:26, Bartc wrote: >>> On 26/10/2015 15:21, Richard Heathfield wrote: >>>> On 26/10/15 14:33, Alla _ wrote: >>>> >>>> <snip> >>>> >>>>> Here is the information on compiler >>>>> >>>>> i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. >>>>> build 5658) (LLVM build 2336.11.00) >>> >>>> So here's a decent set to get you started: >>>> >>>> -W -Wall -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith >>>> -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes >>>> -Wno-missing-field-initializers -Wmissing-declarations -Winline -Wundef >>>> -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings >>> <snip> > Why would you want to do that when you can just write the Makefile > manually? > > CFLAGS=-W -Wall -pedantic -std=c99 > foo: foo.o > $(CC) $(CFLAGS) -o $@ $^ > > That should be all needed for a one-file program. > (foo.o should be foo.c) It also gives a nice easy way for the OP to experiment with adding other warning options from Richard's list. (I am also a fan of detailed lists of warning types, neatly packed in a Makefile. My Makefiles are a good deal more complex than this, but so are my projects - this one is fine for a starting point.) To the OP, I'd add a couple of points about the above Makefile to make it easier for you: 1. The indentation on the $(CC) line is a tab character - not spaces. It is one of the oddities of make, for historical reasons. It's a bit silly, but once you know of it there should be no problem. 2. You can have comment lines starting with #. 3. You can use \ for line continuations. So your Makefile could look like this: # Makefile for building foo, with lots of warnings CFLAGS=-W -Wall -pedantic -std=c99 \ -Wformat-nonliteral -Wcast-align -Wpointer-arith \ -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes \ -Wno-missing-field-initializers -Wmissing-declarations \ -Winline -Wundef \ -Wnested-externs -Wcast-qual -Wshadow -Wwrite-strings # Other flags that might be worth trying later # -pedantic -Wconversion foo: foo.c <tab>$(CC) $(CFLAGS) -o $@ $^
[toc] | [prev] | [next] | [standalone]
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Date | 2015-10-27 20:08 +0000 |
| Message-ID | <slrnn2vme8.5q5.grahn+nntp@frailea.sa.invalid> |
| In reply to | #73959 |
On Tue, 2015-10-27, David Brown wrote: > On 27/10/15 14:36, Jorgen Grahn wrote: >> On Mon, 2015-10-26, Richard Heathfield wrote: >>> On 26/10/15 16:26, Bartc wrote: >>>> On 26/10/2015 15:21, Richard Heathfield wrote: >>>>> On 26/10/15 14:33, Alla _ wrote: >>>>> >>>>> <snip> >>>>> >>>>>> Here is the information on compiler >>>>>> >>>>>> i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. >>>>>> build 5658) (LLVM build 2336.11.00) >>>> >>>>> So here's a decent set to get you started: >>>>> >>>>> -W -Wall -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith >>>>> -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes >>>>> -Wno-missing-field-initializers -Wmissing-declarations -Winline -Wundef >>>>> -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings >>>> > <snip> >> Why would you want to do that when you can just write the Makefile >> manually? >> >> CFLAGS=-W -Wall -pedantic -std=c99 >> foo: foo.o >> $(CC) $(CFLAGS) -o $@ $^ >> >> That should be all needed for a one-file program. >> > > (foo.o should be foo.c) No, that was intentional. The "foo: foo.o" above just does the linking, and there's an implicit rule (or whatever the term for it is) which provides "foo.o: foo.c". With GNU Make at least. But I suppose it would work the way you wrote too. ... > To the OP, I'd add a couple of points about the above Makefile to make > it easier for you: [...] (Thanks. I wasn't sure if this was at all relevant to the OP, so I didn't try to make it understandable.) /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o .
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2015-10-27 22:28 +0100 |
| Message-ID | <n0oq5f$83k$1@dont-email.me> |
| In reply to | #74004 |
On 27/10/15 21:08, Jorgen Grahn wrote: > On Tue, 2015-10-27, David Brown wrote: >> On 27/10/15 14:36, Jorgen Grahn wrote: >>> On Mon, 2015-10-26, Richard Heathfield wrote: >>>> On 26/10/15 16:26, Bartc wrote: >>>>> On 26/10/2015 15:21, Richard Heathfield wrote: >>>>>> On 26/10/15 14:33, Alla _ wrote: >>>>>> >>>>>> <snip> >>>>>> >>>>>>> Here is the information on compiler >>>>>>> >>>>>>> i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. >>>>>>> build 5658) (LLVM build 2336.11.00) >>>>> >>>>>> So here's a decent set to get you started: >>>>>> >>>>>> -W -Wall -pedantic -Wformat-nonliteral -Wcast-align -Wpointer-arith >>>>>> -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes >>>>>> -Wno-missing-field-initializers -Wmissing-declarations -Winline -Wundef >>>>>> -Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings >>>>> >> <snip> >>> Why would you want to do that when you can just write the Makefile >>> manually? >>> >>> CFLAGS=-W -Wall -pedantic -std=c99 >>> foo: foo.o >>> $(CC) $(CFLAGS) -o $@ $^ >>> >>> That should be all needed for a one-file program. >>> >> >> (foo.o should be foo.c) > > No, that was intentional. The "foo: foo.o" above just does the > linking, and there's an implicit rule (or whatever the term for it is) > which provides "foo.o: foo.c". With GNU Make at least. > OK. Since almost all my C programming is for embedded systems, and therefore uses a compiler other than the system standard, I always have the compiler and it's calls given explicitly. So I completely forgot about the implicit rules, as I don't use them. > But I suppose it would work the way you wrote too. > > ... >> To the OP, I'd add a couple of points about the above Makefile to make >> it easier for you: [...] > > (Thanks. I wasn't sure if this was at all relevant to the OP, so I > didn't try to make it understandable.) > The OP has probably given up on the thread by this point - but if not, then I hope it will help. Maybe it will also help Bart see that Makefiles are not as scary as he imagines.
[toc] | [prev] | [next] | [standalone]
| From | Bartc <bc@freeuk.com> |
|---|---|
| Date | 2015-10-27 21:34 +0000 |
| Message-ID | <n0oqi0$b55$1@dont-email.me> |
| In reply to | #74016 |
On 27/10/2015 21:28, David Brown wrote: > The OP has probably given up on the thread by this point - but if not, > then I hope it will help. Maybe it will also help Bart see that > Makefiles are not as scary as he imagines. I don't intend to ever use make files for my own development, which is highly non-standard anyway. So I mainly come across them when trying to build other people's projects. And usually they don't work (for reasons I've mentioned enough times). -- Bartc
[toc] | [prev] | [next] | [standalone]
Page 1 of 6 [1] 2 3 4 5 6 Next page →
Back to top | Article view | comp.lang.c
csiph-web