#include <iostream>
#include <string.h>
#include <fstream>
#include "class.h"

using namespace std;
translator a[100];
int d,b,c;
int n;
int m;
int x;
int z;

void translator::add()
{
	ofstream iFile("singular.bin", ios::binary | ios::app);
	ofstream dFile("definition.bin", ios::binary | ios::app);
	ofstream pFile("plural.bin", ios::binary | ios::app);
	ofstream aFile("articol.bin", ios::binary | ios::app);
	ifstream gFile("nr.bin", ios::binary);
	gFile >> n;
	cout << endl;
	cout << "singular : ";
	cin.getline (word,100);
	cout << endl;
	cout << "plural : ";
	cin.getline (word_pl,100);
	cout << "definition: " ;
	cin.getline (word2,100);
	cout << word << "," << word_pl << "(pl)" <<" - " << word2 << endl;
	iFile << word<< endl;
	pFile << word_pl << endl;
	dFile << word2 << endl;
	ofstream jFile("nr.bin",ios::binary);
	n++;
	jFile << n;
	aFile.close();
	iFile.close();
	pFile.close();
	dFile.close();
	jFile.close();
	gFile.close();
	}

void translator::search()
{
    d = 0;
    b = 0;
    c = 0;
    z = 0;


   int i=0;
   char *search_word;
   search_word = new char[30];

   cout << "Search : ";
   cin >> search_word;

   ifstream iFile("singular.bin", ios::binary);
   ifstream pFile("plural.bin", ios::binary);
   ifstream dFile("definition.bin", ios::binary);
   ifstream jFile("nr.bin", ios::binary);
   ifstream aFile("articol.bin", ios::binary);
    jFile >> n;

   if (aFile.fail() )
   {
        cout << endl << "Error" << aFile << endl;
   }
   else {
       for(i=0;i<n;i++)
       aFile.getline (a[i].articol, 100);
   }

   if (iFile.fail() )
   {
       cout << endl << "Error" << iFile << endl;
   }
   else {
	for(i=0;i<n;i++)
       iFile.getline (a[i].word, 100);
   }

   if (dFile.fail() )
   {
       cout << endl << "Error" << dFile << endl;
   }
       else {
           for (i=0;i<n;i++)
            dFile.getline (a[i].word2,100);
       }


    if (pFile.fail() )
    {
        cout << endl << "Error" << pFile << endl;
    }
        else {
            for (i=0;i<m;i++)
             pFile.getline(a[i].word_pl,100);
        }





        /*if (strcmp ( a[i].articol, search_word ) == 0 ){
            cout << "- - - - - - - - - -" << endl;
            cout << "the / a - -l / -a (articol hotarat);" << endl;
        }

        else
        if ( strstr ( a[i].articol, search_word) == 0 && strstr ( a[i].word, search_word) == 0 ) {

                    cout << "- - - - - - - - - -" << endl;
                    cout << a[i].word << ", " << a[i].word_pl << "(pl)" << " - " << a[i].word2 << endl;

        }

        else */


        /*
        else
        if ( strcmp (a[i].word_pl, search_word ) == 0 ){
           cout << "- - - - - - - - - -" << endl;
           cout << a[i].word_pl << ", " << a[i].word<< "(sg)" << " - " << a[i].word2 << endl;

        } */


        for(i=0; i<n; i++) {

        if (strcmp ( a[i].word, search_word ) == 0){
            cout << "- - - - - - - - - -" << endl;
            cout << a[i].word << ", " << a[i].word_pl << "(pl)" << " - " << a[i].word2 << endl;
            break;
        }


        else {

            z = 1;
        }

        if (strncmp ( a[i].word, search_word,2 ) == 0 && z == 1) {



            cout << "- - - - - - - - - -" << endl;
            cout << a[i].word << ", " << a[i].word_pl << "(pl)" << " - " << a[i].word2 << endl;


        }

        }





   delete search_word;
   aFile.close();
   iFile.close();
   pFile.close();
   dFile.close();
   jFile.close();

}

doing a translator / dictionary program. i got this problem. when i search for a word with the strcmp method and

if (strcmp ( a[i].word, search_word ) == 0){
            cout << "- - - - - - - - - -" << endl;
            cout << a[i].word << ", " << a[i].word_pl << "(pl)" << " - " << a[i].word2 << endl;
            break;
        }


        else {

            z = 1;
        }

doesn't meet the condition it jumps to the next if

if (strncmp ( a[i].word, search_word,2 ) == 0 && z == 1) {



            cout << "- - - - - - - - - -" << endl;
            cout << a[i].word << ", " << a[i].word_pl << "(pl)" << " - " << a[i].word2 << endl;


        }

that uses the strncmp method

the problem is that even if the strcmp method works and it finds the word based on the criteria it still jumps to the strncmp method.
i've tried like 10312312418312 methods and still couldn't make it work.
please some advice .

tnx

i've tried like 10312312418312 methods and still couldn't make it work.

Try putting it in else part. :-/

if (strcmp ( a[i].word, search_word ) == 0)
{
  ..
}
else
{
  ..
  if (strncmp ( a[i].word, search_word,2 ) == 0 && z == 1)
  {
     ..
  }
}
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.