help me in dictionary making
Feb 17, 2015 at 12:20pm UTC
I want to make a program that can read a word from user and will store in a file named "dictionary.txt" in dictionary order. i have done this much. please help me to complete the program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<fstream>
using namespace std;
int main()
{
ifstream fin;
ofstream fout;
system("cls" ); //To clear the user's screen
char word[20]; //The string where word is to be stored
cout<<"\nEnter a word: " ;
cin.getline(word,30);
// The Below 2 lines are only for observation purpose, no role in program
// cout<<"\nthe word is:";
// cout<<word;
fin.open("dictionary.txt" ,ios::out);
if (!fin)
{
cout<<"\nSome Error Has Occured!!! Need To Be Closed." ;
cin.setf(ios::unitbuf);
cin.get();
exit(1);
}
fout.open("temp.txt" ,ios::in);
if (!fout)
{cout<<"h" ;
cout<<"\nSome Error Has Occured!!! Need To Be Closed." ;
cin.setf(ios::unitbuf);
cin.get();
exit(1);
}
char checkw[20]; //To collect a word from file for check
char ch, ch1; //For file read & write purpose
int i=0, j=0; //For checkw string operation
S:
while (ch = fin.get() != EOF)
{
if (ch != '\n' )
{
checkw[i++] = ch;
continue ;
}
int s, s1;
s=strlen(word);
s1=strlen(checkw);
if (s <= s1)
{
for (j=0;j<s; j++)
{
if (word[j] == checkw[j])
continue ;
if (word[j] < checkw[j])
{
for (j=0; j<s; j++)
fout<<word[j];
fout<<'\n' ;
for (j=0; j<s1; j++)
fout<<checkw[j];
while (ch = fin.get() != EOF)
fout<<ch;
goto END;
}
else if (word[j] > checkw[j])
{
for (j=0; j<s1; j++)
fout<<checkw[j];
i=0;
goto S;
}
}
cout<<"\nThe entered word is already present." ;
for (j=0; j<s1; j++)
fout<<checkw[j];
while (ch = fin.get() != EOF)
fout<<ch;
}
END:
i=0;
char ch;
POINT:
cout<<"\nDo you want to insert another word?[y/n]:" ;
cin>>ch;
if (ch == 'y' || ch == 'Y' )
{
cout<<"\nEnter a word: " ;
cin.getline(word,30);
if (fin.eof())
fin.clear();
continue ;
}
else if (ch == 'n' || ch == 'N' )
{
cout<<"\nThanking You for Using the Program" ;
cin.setf(ios::unitbuf);
cin.get();
exit(1);
}
else
{
goto POINT;
}
}
fin.close();
fout.close();
unlink("dictionary.txt" );
rename("temp.txt" , "dictionary.txt" );
return 0;
}
Last edited on Feb 17, 2015 at 6:26pm UTC
Feb 17, 2015 at 1:55pm UTC
What's the problem? Could you edit your post and put it in code tags for easier reading? (The "<>" button)
Feb 17, 2015 at 5:51pm UTC
actually the program is running. but no words are maintaining in the text file. so please analyze the code and tell me.
Feb 17, 2015 at 6:22pm UTC
iQChange wrote:Could you edit your post and put it in code tags for easier reading? (The "<>" button)
Last edited on Feb 17, 2015 at 6:22pm UTC
Topic archived. No new replies allowed.