switch with string problem

qnull interflug1 at gmx.net
Sun Jul 15 06:33:43 PDT 2007


I've got a problem with a test program i created. There is a switch with strings inside. 
When I start the program with the argument "t" the result is:
  q = t
  q_len = 116
  default

I don't understand why the program is taking the default branch of the switch and why q.length = 116 and not q.length = 1.
can somebody give me a hint?
Thank you


Code:
import std.string;

import std.stdio;

import std.c.stdlib;



char[] q;



int main(char[][] args)

{	

	if (args.length == 2) {

		sscanf(&args[1][0],"%s",&q);

	} 

	else {

		printf("just one argument!\n");

		exit(55);

	}

	printf("q = %s\nq_len = %d\n",&q,q.length);


	switch (q)

	{

    	case "t": printf("arg was t!\n"); break;

    	case "l2": printf("arg wasn't t!\n"); break;

    	default: printf("default\n"); break;

	}

	return 0;

}



compiled with gdc 0.23



More information about the Digitalmars-d mailing list