Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

interface help............

Status
Not open for further replies.

jodders

Programmer
Nov 12, 2003
13
0
0
GB
hi gang,keeping getting this error,unterminated character constant, where the * is, and i dont know what i can do..

basically i want the code to output "suffixtree: " and take in input if that makes sense.

I hope someone can help me as i think its just a simple error.

happy new year

Code:
        // Loop over the user's input until told to quit
 error //	while ( input =  * >> ( "suffixtree> ") ) {

		add_history( input );
                command  = strtok( input, " " );
                argument = strtok( NULL, " " );
		
		if (strcmp(command,"print") == 0)
			ST_PrintTree(tree);
		else if (strcmp(command,"find") == 0 ) {
			unsigned long int i;
			//(void)scanf("%s",substring);
			i = ST_FindSubstring(	tree,
						(unsigned char*)argument,
						(DBL_WORD)strlen(argument) );
			printf("%lu \n",i);
		}
		else if (strcmp(command,"findall") == 0 ) {
			//(void)scanf("%s",substring);
			(void)ST_FindAllSubstring(	tree,
						 	(unsigned char*)argument,
							(DBL_WORD)strlen(argument));
		}
		else if (strcmp(command,"test") == 0 )
			(void)ST_SelfTest(tree);
		else if (strcmp(command,"?") == 0 || strcmp(command,"help") == 0 ) {
			PrintHelp();
		}
		else if (strcmp(command,"quit") == 0 ) {
                        break;
		}
		else {
			printf("Unrecognized command %s - enter 'help' for help\n",command);
		}
	}
 
sorry to make it clearer with above,i wantto read in an input.

 
> while ( input = * >> ( "suffixtree> ") ) {
I've no idea what this is - it certainly isn't C.

If you're trying to print "suffixtree> " as a prompt, and then read a line of input, then I would do this

Code:
char *prompt_and_read ( char *input, size_t input_size, char *prompt ) {
  puts(prompt);
  fflush(stdout);
  return fgets( input, input_size, stdin );
}

Which you would call with
Code:
while ( prompt_and_read( input, sizeof input, "suffixtree> " ) != NULL ) {

--
 
hey salem,thanks for your help..my program is almost there,but i m having another problem with one line of code which i dont know how to fix.

Code:
	while ( prompt_and_read( input, sizeof input, "suffixtree> " ) != NULL ) {

---->	      "need help here"   ( input );
                command  = strtok( input, " " );
                argument = strtok( NULL, " " );

Once the Suffix Tree prompt appears,i want the user to be able to type in the command.

Is there any easier way of storing the input the user has typed in?


 
> Once the Suffix Tree prompt appears,i want the user to be able to type in the command.
And what do you think a function called "prompt_and_read" is going to do?

Unless you've messed up the input stream by using scanf(), in which case you'll probably just get a blank line the first time around the loop.

Code:
#include <stdio.h>
#include <stdlib.h>

char *prompt_and_read ( char *input, size_t input_size, char *prompt ) {
    fputs(prompt,stdout);
    fflush(stdout);
    return fgets( input, input_size, stdin );
}

int main ( ) {
    char buff[BUFSIZ];
    while ( prompt_and_read( buff, sizeof buff, "suffixtree> " ) != NULL ) {
        printf( "You typed %s", buff );
    }
    return 0;
}

Example
[tt]$ ./a.out
suffixtree> hello
You typed hello
suffixtree> world
You typed world
suffixtree> hey there, what's happening
You typed hey there, what's happening
[/tt]

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top