D - foreach
- Phill (17/17) Mar 12 2004 Im trying to iterate through a char[][]
- Phill (9/26) Mar 12 2004 Thats strange.......
- Ant (4/15) Mar 12 2004 you forgot %c:
- Phill (66/81) Mar 12 2004 I tried that but it doesnt print correctly ie:
- Andrew Edwards (8/13) Mar 12 2004 [...]
- Andrew Edwards (5/19) Mar 12 2004 sorry, that should be %.*s
- J Anderson (6/7) Mar 13 2004 I always get these mixed up to. I came up with a poem (or whatever you
- John Reimer (7/17) Mar 14 2004 I know. I've had the same trouble remembering it. Then I recalled that ...
- J C Calvarese (46/70) Mar 12 2004 Try:
- Phill (4/74) Mar 13 2004 Thanks for the URL Justin, its great!
- Manfred Nowak (11/15) Mar 12 2004 [...]
- Phill (5/20) Mar 12 2004 bound
- Ant (9/38) Mar 12 2004 that's why my suggestions was wrong
- Phill (10/48) Mar 12 2004 Expanation:
- Manfred Nowak (13/14) Mar 13 2004 Do you agree then, that your conduct may be a suitable object of negativ...
- Phill (21/35) Mar 13 2004 only to a pedant.
- John Reimer (12/18) Mar 13 2004 Phil, don't worry yourself too much about responses such as Manfred's.
- Phill (6/24) Mar 13 2004 :-).
- Phill (4/21) Mar 12 2004 Thanks to everyone!
Im trying to iterate through a char[][] with foreach. It prints the correct amount of index's of "ch", but there is no value there. ie: the following code prints c = c = c = names is a char[] --------------------------------- char[][] ch = split(names,"\n"); foreach(char[] c; ch) { printf("c = \n", c); } Any help is appreciated. Phill.
Mar 12 2004
Thats strange....... ie: this prints fine printf(c); but this doesnt: printf("c = \n", c); Maybe I dont understand this printf :o(( Phill. "Phill" <phill pacific.net.au> wrote in message news:c2tgjg$2pqj$1 digitaldaemon.com...Im trying to iterate through a char[][] with foreach. It prints the correct amount of index's of "ch", but there is no value there. ie: the following code prints c = c = c = names is a char[] --------------------------------- char[][] ch = split(names,"\n"); foreach(char[] c; ch) { printf("c = \n", c); } Any help is appreciated. Phill.
Mar 12 2004
On Sat, 13 Mar 2004 10:29:45 +1100, Phill wrote:Thats strange....... ie: this prints fine printf(c); but this doesnt: printf("c = \n", c); Maybe I dont understand this printf :o(( Phill.you forgot %c: printf("c = %c\n", c); Ant
Mar 12 2004
I tried that but it doesnt print correctly ie: It prints this: c = ? c = c = $ c = % c = ! c = ) c = c = c = c = % c = c = ( c = ( c = $ c = , c = , c = ! c = ? c = ? c = " c = ! c = $ c = & c = ? c = T ------------- instead of this: ---------------------- 200 digitalmars.com InterNetNews NNRP server INN 2.3.2 ready (posting ok). Sending List request..... 215 Newsgroups in form "group high low flags". c++ 0000003792 0000000001 y c++.stl 0000000083 0000000001 y c++.stl.hp 0000000010 0000000001 y c++.stl.sgi 0000000039 0000000001 y c++.stl.port 0000000176 0000000001 y c++.idde 0000000402 0000000001 y c++.command-line 0000000402 0000000001 y c++.rtl 0000000059 0000000001 y c++.mfc 0000000347 0000000001 y c++.atl 0000000041 0000000001 y c++.announce 0000000594 0000000001 y c++.dos 0000000217 0000000001 y c++.dos.16-bits 0000000156 0000000001 y c++.dos.32-bits 0000000416 0000000001 y c++.windows 0000000006 0000000001 y c++.windows.16-bits 0000000071 0000000001 y c++.windows.32-bits 0000000757 0000000001 y c++.chat 0000000348 0000000001 y D 0000025479 0000000001 y D.gnu 0000000488 0000000001 y DMDScript 0000000040 0000000001 y c++.beta 0000000357 0000000001 y c++.stlsoft 0000000188 0000000001 y c++.wxwindows 0000000172 0000000001 y It ok because printf(c) is fine for me I just wanted to see what I was getting back from the server, to see what I was dealing with. I would be interested to find out the reason it is printing that though. I dont know much C/C++ so I only know that basics of printf. Phill. ."Ant" <duitoolkit yahoo.ca> wrote in message news:pan.2004.03.12.23.11.53.688428 yahoo.ca...On Sat, 13 Mar 2004 10:29:45 +1100, Phill wrote:Thats strange....... ie: this prints fine printf(c); but this doesnt: printf("c = \n", c); Maybe I dont understand this printf :o(( Phill.you forgot %c: printf("c = %c\n", c); Ant
Mar 12 2004
On Sat, 13 Mar 2004 10:49:45 +1100, Phill <phill pacific.net.au> wrote:I tried that but it doesnt print correctly ie: It prints this:[...]------------- instead of this: ----------------------[...] Thats because c is of type char[]. instead of: printf("c = \n",c); use this: printf("c = %*.s\n",c); cya, Andrew
Mar 12 2004
On Fri, 12 Mar 2004 23:06:47 -0500, Andrew Edwards <remove_ridimz remove_yahoo.com> wrote:On Sat, 13 Mar 2004 10:49:45 +1100, Phill <phill pacific.net.au> wrote:sorry, that should be %.*s -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/I tried that but it doesnt print correctly ie: It prints this:[...]------------- instead of this: ----------------------[...] Thats because c is of type char[]. instead of: printf("c = \n",c); use this: printf("c = %*.s\n",c); cya, Andrew
Mar 12 2004
Andrew Edwards wrote:sorry, that should be %.*sI always get these mixed up to. I came up with a poem (or whatever you call it): star before s but not before dot -- -Anderson: http://badmama.com.au/~anderson/
Mar 13 2004
J Anderson wrote:Andrew Edwards wrote:I know. I've had the same trouble remembering it. Then I recalled that if one thinks of s as representing a pointer type then its easy to remember that the asterisk should be right next to "variable" (for those familiar with C/C++ at least). That has helped me. Later, Johnsorry, that should be %.*sI always get these mixed up to. I came up with a poem (or whatever you call it): star before s but not before dot
Mar 14 2004
Phill wrote:Im trying to iterate through a char[][] with foreach. It prints the correct amount of index's of "ch", but there is no value there. ie: the following code prints c = c = c = names is a char[] --------------------------------- char[][] ch = split(names,"\n"); foreach(char[] c; ch) { printf("c = \n", c);Try: printf("%.*s = \n", c); It's a char[] so "%.*s" it the proper format string. (See also http://www.wikiservice.at/d/wiki.cgi?HowTo/printf)} Any help is appreciated. Phill.Here's a full example, so that everyone can try it out: import std.string; void main() { char[] names = "200 digitalmars.com InterNetNews NNRP server INN 2.3.2 ready (posting ok). Sending List request..... 215 Newsgroups in form \"group high low flags\". c++ 0000003792 0000000001 y c++.stl 0000000083 0000000001 y c++.stl.hp 0000000010 0000000001 y c++.stl.sgi 0000000039 0000000001 y c++.stl.port 0000000176 0000000001 y c++.idde 0000000402 0000000001 y c++.command-line 0000000402 0000000001 y c++.rtl 0000000059 0000000001 y c++.mfc 0000000347 0000000001 y c++.atl 0000000041 0000000001 y c++.announce 0000000594 0000000001 y c++.dos 0000000217 0000000001 y c++.dos.16-bits 0000000156 0000000001 y c++.dos.32-bits 0000000416 0000000001 y c++.windows 0000000006 0000000001 y c++.windows.16-bits 0000000071 0000000001 y c++.windows.32-bits 0000000757 0000000001 y c++.chat 0000000348 0000000001 y D 0000025479 0000000001 y D.gnu 0000000488 0000000001 y DMDScript 0000000040 0000000001 y c++.beta 0000000357 0000000001 y c++.stlsoft 0000000188 0000000001 y c++.wxwindows 0000000172 0000000001 y"; char[][] ch = split(names,"\n"); foreach(char[] c; ch) { printf("%.*s = \n", c); } } -- Justin http://jcc_7.tripod.com/d/
Mar 12 2004
Thanks for the URL Justin, its great! Phill. "J C Calvarese" <jcc7 cox.net> wrote in message news:c2tli3$12e$1 digitaldaemon.com...Phill wrote:Im trying to iterate through a char[][] with foreach. It prints the correct amount of index's of "ch", but there is no value there. ie: the following code prints c = c = c = names is a char[] --------------------------------- char[][] ch = split(names,"\n"); foreach(char[] c; ch) { printf("c = \n", c);Try: printf("%.*s = \n", c); It's a char[] so "%.*s" it the proper format string. (See also http://www.wikiservice.at/d/wiki.cgi?HowTo/printf)} Any help is appreciated. Phill.Here's a full example, so that everyone can try it out: import std.string; void main() { char[] names = "200 digitalmars.com InterNetNews NNRP server INN 2.3.2 ready (posting ok). Sending List request..... 215 Newsgroups in form \"group high low flags\". c++ 0000003792 0000000001 y c++.stl 0000000083 0000000001 y c++.stl.hp 0000000010 0000000001 y c++.stl.sgi 0000000039 0000000001 y c++.stl.port 0000000176 0000000001 y c++.idde 0000000402 0000000001 y c++.command-line 0000000402 0000000001 y c++.rtl 0000000059 0000000001 y c++.mfc 0000000347 0000000001 y c++.atl 0000000041 0000000001 y c++.announce 0000000594 0000000001 y c++.dos 0000000217 0000000001 y c++.dos.16-bits 0000000156 0000000001 y c++.dos.32-bits 0000000416 0000000001 y c++.windows 0000000006 0000000001 y c++.windows.16-bits 0000000071 0000000001 y c++.windows.32-bits 0000000757 0000000001 y c++.chat 0000000348 0000000001 y D 0000025479 0000000001 y D.gnu 0000000488 0000000001 y DMDScript 0000000040 0000000001 y c++.beta 0000000357 0000000001 y c++.stlsoft 0000000188 0000000001 y c++.wxwindows 0000000172 0000000001 y"; char[][] ch = split(names,"\n"); foreach(char[] c; ch) { printf("%.*s = \n", c); } } -- Justin http://jcc_7.tripod.com/d/
Mar 13 2004
Phill wrote: [...]foreach(char[] c; ch) { printf("c = \n", c); }[...] printf("c = %.*s\n", c); There are some conventions most programmers trust in: `i' is a name used for a variable of integer type containing running content `n' is a name used for a variable of integer type containing an upper bound `c' is a name used for a variable of character type ... So long.
Mar 12 2004
"Manfred Nowak" <svv1999 hotmail.com> wrote in message news:c2tml8$383$1 digitaldaemon.com...Phill wrote: [...]boundforeach(char[] c; ch) { printf("c = \n", c); }[...] printf("c = %.*s\n", c); There are some conventions most programmers trust in: `i' is a name used for a variable of integer type containing running content `n' is a name used for a variable of integer type containing an upper`c' is a name used for a variable of character type ... So long.Yes, and??? Phill
Mar 12 2004
On Sat, 13 Mar 2004 15:31:51 +1100, Phill wrote:"Manfred Nowak" <svv1999 hotmail.com> wrote in message news:c2tml8$383$1 digitaldaemon.com...that's why my suggestions was wrong I saw 'char' and 'c' so my brain ignored the '[]' (actually I just looked at the printf and saw 'c') You wouldn't do: char[] myCharacter; char myString; would you? AntPhill wrote: [...]boundforeach(char[] c; ch) { printf("c = \n", c); }[...] printf("c = %.*s\n", c); There are some conventions most programmers trust in: `i' is a name used for a variable of integer type containing running content `n' is a name used for a variable of integer type containing an upper`c' is a name used for a variable of character type ... So long.Yes, and??? Phill
Mar 12 2004
Expanation: At first I actually tried to read each character from the char[] which is returned , but then I decided that I would use split(which as you know returns a char[][]) so that I could read the whole line(group name) in a char[] instead of a char at a time, unfortunately when I changed from char to char[] I left the char[] name as c because I was in a hurry to test and partly because I am lazy :o)) Phill. "Ant" <duitoolkit yahoo.ca> wrote in message news:pan.2004.03.13.04.22.24.989634 yahoo.ca...On Sat, 13 Mar 2004 15:31:51 +1100, Phill wrote:"Manfred Nowak" <svv1999 hotmail.com> wrote in message news:c2tml8$383$1 digitaldaemon.com...that's why my suggestions was wrong I saw 'char' and 'c' so my brain ignored the '[]' (actually I just looked at the printf and saw 'c') You wouldn't do: char[] myCharacter; char myString; would you? AntPhill wrote: [...]boundforeach(char[] c; ch) { printf("c = \n", c); }[...] printf("c = %.*s\n", c); There are some conventions most programmers trust in: `i' is a name used for a variable of integer type containing running content `n' is a name used for a variable of integer type containing an upper`c' is a name used for a variable of character type ... So long.Yes, and??? Phill
Mar 12 2004
Phill wrote: [...]because I was in a hurry to test and partly because I am lazyDo you agree then, that your conduct may be a suitable object of negative criticism? Instead of reasoning over your code yourself, you was so lazy to post to the world a fact about `foreach' whereas you had no evidence, that your code worked without the `foreach', thereby allocating the time of at least three helpful and unlazy people, not accounting those who already spent or will spend time to read your posting and the answers for only recognizing, a person in a hurry, that was drinking coffee while the world started circling around its generated non issue. How do you want to pay that back? So long.
Mar 13 2004
"Manfred Nowak" <svv1999 hotmail.com> wrote in message news:c2uhre$1fdg$1 digitaldaemon.com...Phill wrote: [...]only to a pedant.because I was in a hurry to test and partly because I am lazyDo you agree then, that your conduct may be a suitable object of negative criticism?Instead of reasoning over your code yourself, you was so lazy to post to the world a fact about `foreach' whereas you had no evidence, that your code worked without the `foreach', thereby allocating the time of at least three helpful and unlazy people, not accounting those who already spent or will spend time to read your posting and the answers for only recognizing, a person in a hurry, that was drinking coffee while the world started circling around its generated non issue.If you READ my post and READ the code you will see that the only REAL problem with my code was I had this: printf("c = \n",c); instead of this: printf("c = %*.s\n",c); The reason that I used this: printf("c = \n",c); Is because I did not know about this: printf("c = %*.s\n",c); My lack of knowledge of the formatting of strings is as I stated in an earlier post because I have hardly any programming experience in C or C++. I only know Java, but I am trying to learn this D language. As this is about the only place one can come to get any questions answered about the use of it, this is where I come. You bitching about peoples lack of knowledge is not going to do anything for the popularity of D, so why dont you get off you high horse......... So long!How do you want to pay that back? So long.
Mar 13 2004
You bitching about peoples lack of knowledge is not going to do anything for the popularity of D, so why dont you get off you high horse......... So long!Phil, don't worry yourself too much about responses such as Manfred's. Your question was innocent enough. No one is forced to read or even answer posts, so whoever complains the way he did has to take responsibility for themselves. Just give him the benefit of the doubt and assume that he had a stressful day and was tired. It happens to everyone now and again. Actually, cranky retorts are quite rare in this D group, thank goodness :-). In truth, the way Manfred wrote his response, I almost thought he was joking around. It was rather a mouthful to read, consisting of one looooong sentence linked together with several clauses. Try reading it aloud without taking a breath ;-). Peacefully, John
Mar 13 2004
"John Reimer" <jjreimer telus.net> wrote in message news:pan.2004.03.13.09.51.20.547117 telus.net...:-).You bitching about peoples lack of knowledge is not going to do anything for the popularity of D, so why dont you get off you high horse......... So long!Phil, don't worry yourself too much about responses such as Manfred's. Your question was innocent enough. No one is forced to read or even answer posts, so whoever complains the way he did has to take responsibility for themselves. Just give him the benefit of the doubt and assume that he had a stressful day and was tired. It happens to everyone now and again. Actually, cranky retorts are quite rare in this D group, thank goodnessIn truth, the way Manfred wrote his response, I almost thought he was joking around. It was rather a mouthful to read, consisting of one looooong sentence linked together with several clauses. Try reading it aloud without taking a breath ;-).Yes, its very similar to taking the semi colons out of your code isnt it? :o)) Phill.Peacefully, John
Mar 13 2004
Thanks to everyone! Phill. "Phill" <phill pacific.net.au> wrote in message news:c2tgjg$2pqj$1 digitaldaemon.com...Im trying to iterate through a char[][] with foreach. It prints the correct amount of index's of "ch", but there is no value there. ie: the following code prints c = c = c = names is a char[] --------------------------------- char[][] ch = split(names,"\n"); foreach(char[] c; ch) { printf("c = \n", c); } Any help is appreciated. Phill.
Mar 12 2004