D - 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"); }
Jan 09 2004
"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)
Jan 09 2004
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"); }
Jan 09 2004