Random characters enter the file I am writing in c++
<pre><code>#include &lt;string.h&gt;
#include &lt;conio.h&gt;
#include &lt;fstream.h&gt;
#include &lt;string.h&gt;



class mobile
{
int id;
float price;
char *model,*brand;
public:
int getId()
{
    return id;
}
float getPrice(){return price;}
mobile()
{
    brand = new char[5];
    model = new char[5];
    id = 0;
    price = 0.0;
}
void addDetail()
{
    cout&lt;&lt;"\nEnter the mobile ID ";cin&gt;&gt;id;
    cout&lt;&lt;"\nEnter the Price of mobile ";cin&gt;&gt;price;
    cout&lt;&lt;"\nEnter the Brand name of mobile ";cin&gt;&gt;brand;
    cout&lt;&lt;"\nEnter the Model of mobile ";cin&gt;&gt;model;
    ofstream file("database.txt",ios::app);
    char c=' ',n='\n';
    file&lt;&lt;id&lt;&lt;c;
    file&lt;&lt;price&lt;&lt;c;
    file&lt;&lt;brand&lt;&lt;c;
    file&lt;&lt;model&lt;&lt;n;
    file.close();

}

char* getbrand(){return brand;}
char* getModel(){return model;}
~mobile()
{
    delete brand;
    delete model;
}

};

void count()
{
int counter = 0;
char c;
ifstream file("database.txt");
file.seekg(0,ios::beg);
if(!file)cout&lt;&lt;"File not present";
while(file)
{
    file.get(c);
    if(c == '\n')
    {
        counter++;
    }
}
cout&lt;&lt;"The no of entries "&lt;&lt;counter;
file.close();
}

void addMobile()
{
char *model,*brand;

mobile m;
m.addDetail();    
}

void EditMobile()
{
fstream file;
char* brand,*model;
file.open("database.txt",ios::in);
brand = new char;
model = new char;
char c;
int id,pos;
float price;
float f;
if(!file)cout&lt;&lt;"File not present";
else
{


file&gt;&gt;id;cout&lt;&lt;"ID :"&lt;&lt;id&lt;&lt;endl;
file&gt;&gt;price;cout&lt;&lt;"Price :"&lt;&lt;price&lt;&lt;endl;
file&gt;&gt;brand;cout&lt;&lt;"Brand :"&lt;&lt;brand&lt;&lt;endl;
file&gt;&gt;model;cout&lt;&lt;"Model :"&lt;&lt;model&lt;&lt;endl;

}

delete brand;
delete model;
file.close();

}

void admin()
{

char* userpassword;
userpassword = new char;
char* pass;
pass = new char;

cout&lt;&lt;"\n\nEnter the Password";
cin&gt;&gt;userpassword;
fstream fin;
fin.open("password.txt",ios::in | ios::out);
if(!fin)
cout&lt;&lt;"\n\nFile does not exist";
else
{
fin&gt;&gt;pass;
if(strcmp(userpassword,pass) == 0)
{
    char ch;

    count();
    clrscr();
    cout&lt;&lt;"\n\nAcces Granted!!\n\n\tWelcome";
    cout&lt;&lt;"\n\n1.Add a Mobile.";
    cout&lt;&lt;"\n2.Edit a Mobile.";
    cout&lt;&lt;"\n3.Delete a Mobile.";
    cout&lt;&lt;"\n4.View the Database.\n\nEnter Your Choice ";
    ch = getch();
    switch(ch)
    {
    case '1':
        addMobile();
        break;
    case '2':
        EditMobile();
        break;
    case '3':
        //deleteMobile();
        break;

    }
}
else
{
    cout&lt;&lt;"\n\nAcces Denied";
    return;
}
}

fin.close();
delete userpassword;
}
int main()
{
char choice;
clrscr();
cout&lt;&lt;"Welcome to Mobile Store management Program";
cout&lt;&lt;"\n1.Find a Mobile.";
cout&lt;&lt;"\n2.Know Price.";
cout&lt;&lt;"\n3.Know Description.";
cout&lt;&lt;"\n4.Administrator Login.\n\nEnter Your Choice";
choice = getch();
switch(choice)
{
case '1':

    break;
case '4':
    admin();
    break;
}
getch();
return 0;
}
</code></pre>

<p>Now in the output I type:</p>

<pre><code>Acces Granted!!

        Welcome

1.Add a Mobile.
2.Edit a Mobile.
3.Delete a Mobile.
4.View the Database.

Enter Your Choice
Enter the mobile ID 1

Enter the Price of mobile 123.34

Enter the Brand name of mobile Nokia

Enter the Model of mobile mynokiamobile
</code></pre>

<p>And the output I get in my database.txt file is:</p>

<pre><code>1 123.339996 Nokia mynoki   ile
</code></pre>

<p>This space in between are random characters cant be seen here.</p>
