Thread overview |
---|
January 09, 2004 scanf and then using result in case, not working in D | ||||
---|---|---|---|---|
| ||||
With scanf you can't use the scanf result in D case !?!?!? import std.c.stdio; char[80] name; printf("Yo! What's your name? "); scanf("%s", &name); printf("\nHey, %.*s, ", name); // Give name, example John -> Never go in right Case (always Default!!!) switch(name) { case "John": printf("JOHN IS THE NAME!\n"); break; case "Bill": printf("BILL IS THE NAME!\n"); break; case "Cindy": printf("CINDY IS THE NAME!\n"); break; default: printf("Nobody\n"); } |
January 09, 2004 Re: scanf and then using result in case, not working in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to ork | "ork" <ork_member@pathlink.com> wrote in message news:btn862$1ud9$1@digitaldaemon.com... > With scanf you can't use the scanf result in D case !?!?!? > > > import std.c.stdio; > > char[80] name; > > printf("Yo! What's your name? "); > scanf("%s", &name); > printf("\nHey, %.*s, ", name); > > // Give name, example John -> Never go in right Case (always Default!!!) > > switch(name) > { > case "John": > printf("JOHN IS THE NAME!\n"); > break; > case "Bill": > printf("BILL IS THE NAME!\n"); > break; > case "Cindy": > printf("CINDY IS THE NAME!\n"); > break; > default: > printf("Nobody\n"); > } > You need to convert the buffer into a D string: std.string.toString(cast(char*)name) |
January 09, 2004 Re: scanf and then using result in case, not working in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to ork | Try toString ? Im guessing the null terminator is included in name, thus not matching the compares( guessing though ). C "ork" <ork_member@pathlink.com> wrote in message news:btn862$1ud9$1@digitaldaemon.com... > With scanf you can't use the scanf result in D case !?!?!? > > > import std.c.stdio; > > char[80] name; > > printf("Yo! What's your name? "); > scanf("%s", &name); > printf("\nHey, %.*s, ", name); > > // Give name, example John -> Never go in right Case (always Default!!!) > > switch(name) > { > case "John": > printf("JOHN IS THE NAME!\n"); > break; > case "Bill": > printf("BILL IS THE NAME!\n"); > break; > case "Cindy": > printf("CINDY IS THE NAME!\n"); > break; > default: > printf("Nobody\n"); > } > > |
Copyright © 1999-2021 by the D Language Foundation