I'm writing a lite version of the stty command for school, and I keep getting this error at compile:

showtty.c:40: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token

My code:

#include	<stdio.h>
#include 	<stdlib.h>
#include	<termios.h>

/**
 **	showtty	
 **	displays some of current tty settings
 **/

main(int argc, char *argv[])
{
	struct	termios ttyinfo;				/*this struct holds tty info*/
	if (argc == 1)
	{						
		if ( tcgetattr( 0 , &ttyinfo ) == -1 )		/*get info*/
		{   					
			perror("cannot get params about stdin");
			exit(1);
		}
		show(&ttyinfo);					/*show info*/
		printf("\n");
	}
	else
	{
		int ii = 1;
		int offon = 1;
		while (ii < argc)
		{
			if (argv[ii][0] == '-')
				offon = 0;

			setbit( offon, &ttyinfo, argv[ii]);

		}


	}
}

setbit(int flip, struct termios *ttyi, char &option)
{
	if (flip == 0)
	{
		switch (option))
		{
			case "echo"	: ttyi->c_lflag &= ~ECHO; break;
			case "icrnl"	: ttyi->c_iflag &= ~ICRNL;break;
			case "onlcr"	: ttyi->c_oflag &= ~ONLCR;break;
			case "echoe"	: ttyi->c_lflag &= ~ECHOE;break;
			case "olcuc"	: ttyi->c_oflag &= ~OLCUC;break;
			case "crtscts"	: ttyi->c_cflag &= ~CRTSCTS;break;
			case "icanon"	: ttyi->c_lflag &= ~ICANON;break;
			case "isig"	: ttyi->c_lflag &= ~ISIG;break;
			default		:printf("ERROR: Unknown option.");break;			
		}
	}
	else
	{
		switch (option)
		{
			case "echo"	: ttyi->c_lflag |= ECHO; break;
			case "icrnl"	: ttyi->c_iflag |= ICRNL;break;
			case "onlcr"	: ttyi->c_oflag |= ONLCR;break;
			case "echoe"	: ttyi->c_lflag |= ECHOE;break;
			case "olcuc"	: ttyi->c_oflag |= OLCUC;break;
			case "crtscts"	: ttyi->c_cflag |= CRTSCTS;break;
			case "icanon"	: ttyi->c_lflag |= ICANON;break;
			case "isig"	: ttyi->c_lflag |= ISIG;break;
			default		:printf("ERROR: Unknown option.");break;			
		}
	}
	if (tcsetattr(0, TCSANOW, &ttyi) == -1)
	{
		perror("tcsetattr");
			exit(2);
	}


}
show(struct termios *showinfo)
{

	showbaud 	(cfgetospeed(showinfo));		/*retrieve and show speed */
	showchar 	(showinfo);				/*show assigned characters*/
	show_some_flags	(showinfo);				/*show misc. flags */
}

showbaud( thespeed )
/*
 *	prints the speed in english
 */
{
	printf(" The baud rate is ");
	switch ( thespeed ){
		case B300:	printf("300\n");	break;
		case B600:	printf("600\n"); 	break;
		case B1200:	printf("1200\n"); 	break;
		case B1800:	printf("1800\n"); 	break;
		case B2400:	printf("2400\n"); 	break;
		case B4800:	printf("4800\n"); 	break;
		case B9600:	printf("9600\n"); 	break;
		case B19200:    printf("19200\n");	break;
		case B38400:    printf("38400\n");	break;
            	case B57600:	printf("57600\n");	break;
            	case B115200:	printf("115200\n");	break;
            	case B230400:	printf("230400\n");	break;
		default:	printf("TIME WARP\n");	break;
	}
}

showchar( struct termios *ttyinf )
{
	printf(" erase     = ascii %d,\t = ^%c\n",
			ttyinf->c_cc[VERASE], ttyinf->c_cc[VERASE]-1+'A');
	printf(" kill      = ascii %d,\t = ^%c\n",
			ttyinf->c_cc[VKILL], ttyinf->c_cc[VKILL]-1+'A');
	printf(" interrupt = ascii %d,\t = ^%c\n",
			ttyinf->c_cc[VINTR], ttyinf->c_cc[VINTR]-1+'A');
	printf(" time = %d\n", ttyinf->c_cc[VTIME]);
	printf(" min = %d\n", ttyinf->c_cc[VMIN]);

}

struct flaginfo { tcflag_t fl_value; char *fl_name; };


struct flaginfo control_flags[] = {
		CREAD	,	"cread",
		CRTSCTS	,	"crtscts",
		HUPCL	,	"hupcl",
		PARENB	,	"parenb",
		0	,	NULL };

struct flaginfo input_flags[] = {

		IGNBRK	,	"ignbrk",
		ICRNL	,	"icrnl",
		IXON	,	"ixon",
		IXOFF   ,	"ixoff",
		0	,	NULL };

struct flaginfo local_flags[] = {
		ISIG	,	"isig",
		ICANON	,	"icanon",
		ECHO	,	"echo",
		ECHOE	,	"echoe",
		0	,	NULL };

struct flaginfo output_flags[] = {
 		OLCUC 	,	"olcuc",
       		ONLCR  	,	"onlcr",
       		NLDLY  	,	"nldly",
       		CRDLY  	,	"crdly",
		0	,	NULL };


show_some_flags( struct termios *ttyp )
/*
 *	show the values of two of the flag sets_: c_iflag and c_lflag
 *	adding c_oflag and c_cflag is pretty routine - just add new
 *	tables above and a bit more code below.
 */
{
	show_flagset( ttyp->c_cflag, control_flags );
	show_flagset( ttyp->c_iflag, input_flags );
	show_flagset( ttyp->c_lflag, local_flags );
	show_flagset( ttyp->c_oflag, output_flags );
}

show_flagset( int thevalue, struct flaginfo thebitnames[] )
/*
 * check each bit pattern and display descriptive title
 */
{
	int	i;
	
	for ( i=0; thebitnames[i].fl_value ; i++ ) {
		if ( thevalue & thebitnames[i].fl_value )
			printf(" ");	
		else
			printf("-");
		printf( "%-5s\n", thebitnames[i].fl_name);
	}
}

Any thoughts?

one thing is

you are receiving something as &option.. this is not possible. if you mean to pass a pointer , u should receive it as *option as you have used for your second argument ttyi

also find another way other than switch to compare the values since you are passing string

one more thing i noted is that for switch, u have used 2 closing braces ')'.
this is also not needed

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.