CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2015
    Posts
    1

    Lightbulb identifier not found

    After i compiled this code for first time the library "windows.h" was missing and i got some strange errors, but now after i added it i get those, but i can't really figure out why, i posted the code and the errors below.
    Code:
    #include <iostream>
    #include <conio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <windows.h>
    #define LEFT  1
    #define RIGHT 2
    using namespace std;
    
    struct node
    {
    	char word[20], meaning[100];
    	node *left, *right;
    };
    
    node *maketree ( char[], char[] );
    
    node* treefromfile ( );
    void filefromtree ( node* );
    void addword ( node*, char[], char[] );
    void seperateword ( char[], char[], char[] );
    void displayall ( node* );
    node* bsearch ( node*, char[] );
    void showmenu ( );
    FILE *file_ptr;
    
    void prog ( )
    {
    	clrscr ( );
    	char word[20], meaning[100];
    	int menuchoice;
    	node *temp;
    	temp = treefromfile ( );
    	if( temp == NULL )
    	{
    		cout << "File does not exist or dictionary is empty...";
    		getch ( );
    	}
    	while( 1 )
    	{
    		clrscr ( );
    		showmenu ( );
    		cin>>menuchoice;
    			switch( menuchoice )
    		{
    			case 1:cout << "Enter word : ";
    				cin >> word;
    				cout << "Enter meaning : ";
    				flushall ( );
    				gets ( meaning );
    				if( temp == NULL )
    					temp = maketree ( word, meaning );
    				else
    					addword ( temp, word, meaning );
    				break;
    			case 2:if( temp == NULL )
    				cout << "The dictionary is empty...";
    				   else
    				   {
    					   cout << "Find meaning of : ";
    					   flushall ( );
    					   gets ( word );
    					   node *t;
    					   t = bsearch ( temp, word );
    					   if( t == NULL )
    						   cout << "Word not found...";
    					   else
    					   {
    						   cout << t->word;
    						   puts ( t->meaning );
    					   }
    				   }
    				   getch ( );
    				   break;
    			case 3:if( temp == NULL )
    				cout << "Dictionary is empty...";
    				   else
    					   displayall ( temp );
    				getch ( );
    				break;
    			case 4:filefromtree ( temp );
    				exit ( 1 );
    				break;
    			default:cout << "Enter Again";
    				
    				prog ( );
    				break;
    		}
    	}
    }
    void showmenu ( )
    {
    	cout << "COMPUTER DICTIONARY";
    	cout << "[1].Add a word.";
    	cout << "[2].Find meaning.";
    	cout << "[3].Display all.";
    	cout << "[4].Save and Close.";
    	cout << "Enter Choice";
    }
    node* treefromfile ( )
    {
    	node *ptree = NULL;
    	char word[20], meaning[100], str[120], *i;
    	int flags = 0;
    	file_ptr = fopen ( "C:\dict.anu", "r" );
    	if( file_ptr == NULL )
    		ptree = NULL;
    	else
    	{
    
    		while( !feof ( file_ptr ) )
    		{
    			i = fgets ( str, 120, file_ptr );
    			if( i == NULL )
    				break;
    			seperateword ( str, word, meaning );
    			if( flags == 0 )
    			{
    				ptree = maketree ( word, meaning );
    				flags = 1;
    			}
    			else
    				addword ( ptree, word, meaning );
    		}
    
    		fclose ( file_ptr );
    	}
    	return ptree;
    }
    node* maketree ( char w[], char m[] )
    {
    	node *p;
    	p = new node;
    	strcpy ( p->word, w );
    	strcpy ( p->meaning, m );
    	p->left = NULL;
    	p->right = NULL;
    	return p;
    }
    void seperateword ( char str[], char w[], char m[] )
    {
    	int i, j;
    	for( i = 0; str[i] != ' '; i++ )
    		w[i] = str[i];
    	w[i++] = NULL;	//Append the null and skip the space.
    	for( j = 0; str[i] != '		';i++,j++)
    	{
    		m[j] = str[i];
    	}
    	m[j] = NULL;
    }
    void addword ( node *tree, char word[], char meaning[] )
    {
    	node *p, *q;
    	p = q = tree;
    	while( strcmp ( word, p->word ) != 0 && p != NULL )
    	{
    		q = p;
    		if( strcmp ( word, p->word ) < 0 )
    			p = p->left;
    		else
    			p = p->right;
    	}
    	if( strcmp ( word, q->word ) == 0 )
    	{
    		cout<<"This word already exists...";
    			
    	}
    	else if( strcmp ( word, q->word ) < 0 )
    		q->left = maketree ( word, meaning );
    	else
    		q->right = maketree ( word, meaning );
    }
    node* bsearch ( node *tree, char word[] )
    {
    	node *q;
    	q = tree;
    	while( q != NULL )
    	{
    		//p=q;
    		if( strcmp ( word, q->word ) < 0 )
    			q = q->left;
    		else if( strcmp ( word, q->word ) > 0 )
    			q = q->right;
    		if( strcmp ( word, q->word ) == 0 )
    			break;
    	}
    	return q;
    }
    void filefromtree ( node *tree )
    {
    	void travandwrite ( node* );
    	file_ptr = fopen ( "C:\dict.anu", "w" );
    	if( file_ptr == NULL )
    	{
    		cout<<"Cannot open file for writing data...";
    	}
    	else //if(tree==NULL)
    	{
    		if( tree != NULL )
    		{
    			travandwrite ( tree );
    		}
    		fclose ( file_ptr );  //Close the file anyway.
    	}
    }
    void travandwrite ( node *tree )
    {
    	if( tree != NULL )
    	{
    		cout << tree->word << " = " << tree->meaning;
    			travandwrite ( tree->left );
    		travandwrite ( tree->right );
    	}
    }
    void displayall ( node *tree )
    {
    	if( tree != NULL )
    	{
    		displayall ( tree->left );
    		cout<<tree->word<<" = "<<tree->meaning;
    			displayall ( tree->right );
    	}
    }
    
    void intro ( )
    {
    	int i;
    	clrscr ( );
    	gotoxy ( 20, 20 );
    	cout << "DICTIONARY LOADING";
    	for( i = 0; i < 50; i++ )
    	{
    		gotoxy ( 15 + i, 21 );
    		cout << "รพรพรพ";
    		gotoxy ( 20, 22 );
    		cout << 2 * i << "% completed";
    		
    	}
    	gotoxy ( 20, 20 );
    	cout << "DICTIONARY LOADING COMPLETED";
    	clrscr ( );
    }
    void main ( )
    {
    	clrscr ( );
    	intro ( );
    	prog ( );
    }
    Code:
    1>  dictionary.cpp
    1>c:\users\alex\desktop\test\dictionary\dictionary\dictionary.cpp(29): error C3861: 'clrscr': identifier not found
    1>c:\users\alex\desktop\test\dictionary\dictionary\dictionary.cpp(41): error C3861: 'clrscr': identifier not found
    1>c:\users\alex\desktop\test\dictionary\dictionary\dictionary.cpp(105): warning C4129: 'd' : unrecognized character escape sequence
    1>c:\users\alex\desktop\test\dictionary\dictionary\dictionary.cpp(193): warning C4129: 'd' : unrecognized character escape sequence
    1>c:\users\alex\desktop\test\dictionary\dictionary\dictionary.cpp(229): error C3861: 'clrscr': identifier not found
    1>c:\users\alex\desktop\test\dictionary\dictionary\dictionary.cpp(230): error C3861: 'gotoxy': identifier not found
    1>c:\users\alex\desktop\test\dictionary\dictionary\dictionary.cpp(234): error C3861: 'gotoxy': identifier not found
    1>c:\users\alex\desktop\test\dictionary\dictionary\dictionary.cpp(236): error C3861: 'gotoxy': identifier not found
    1>c:\users\alex\desktop\test\dictionary\dictionary\dictionary.cpp(240): error C3861: 'gotoxy': identifier not found
    1>c:\users\alex\desktop\test\dictionary\dictionary\dictionary.cpp(242): error C3861: 'clrscr': identifier not found
    1>c:\users\alex\desktop\test\dictionary\dictionary\dictionary.cpp(246): error C3861: 'clrscr': identifier not found

  2. #2
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: identifier not found

    for clrscr/gotoxy, you need to
    Code:
    #include <conio.h>
    and for this:
    Code:
    file_ptr = fopen ( "C:\dict.anu", "r" );
    you need to either use double backslashes or a forward slash.
    A single backslash masks the following character, and the compiler is evaluating the string you are passing.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: identifier not found

    conio.h for Microsoft VS does not contain clrscr()/gotoxy(). These are from the Borland Turbo compilers and are non-standard. For further info see

    http://stackoverflow.com/questions/7...otoxy-function
    http://stackoverflow.com/questions/9...-function-in-c
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: identifier not found

    Thanks for correcting me, 2kaud.
    I just did a quick google without further reading when I spotted conio.h.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured