Fstreams C++ has extra spaces on writing
<p>I figured some stuff out, but I suck at fstreams, and this is just killing me, for BREED + DESC, they have a space between them and name, but when I remove them completely then I get no spaces and it works again. Could someone tell me what I'm doing wrong?</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;cstring&gt;
#include &lt;cctype&gt;
using namespace std;


const int NAME_SIZE = 100;
const int BREED_SIZE = 100;
const int DESC_SIZE = 250;
const int REASON_SIZE = 250;

//creating the struct
struct animal
{
//members
    char name[NAME_SIZE];
    char breed[BREED_SIZE];
    char desc[DESC_SIZE];
    char reason[REASON_SIZE];
    float age;
    float weight;
    int day;
    int month;
    int year;
    float length;
};

class petAdoption
{
    public:
        petAdoption();
        void enroll(animal newAnimal[], int &amp; count);
        void read(animal newAnimal[], int &amp; count);
        //void display(animal &amp; newAnimal);
        //void adopt(animal &amp; newAnimal); 
    private:


};
petAdoption::petAdoption()
{

}

int main()
{
int count = 0;
animal * newAnimal = new animal[count];
petAdoption adopt;
adopt.read(newAnimal, count);
adopt.enroll(newAnimal, count);
delete[] newAnimal;
}


void petAdoption::read(animal newAnimal[], int &amp; count)
{
    int pets = 0;
    ifstream read;
    read.open("pets.txt");
    if(!read)
    {
        cout &lt;&lt; "Checking... File doesn't exist!" &lt;&lt;endl;
    }
    else 
    {
        while(!read.eof())
        {
        read.getline(newAnimal[pets].name, NAME_SIZE, '\n');
        read.ignore(100, '\n');
        ++pets;
        }
    count = pets + 1;
    }
    read.close();

    for (int i = 0; i &lt; pets; ++i){
        read.open(newAnimal[i].name);
            if( !read)
            {
                cout &lt;&lt; "Checking... File doesn't exist!" &lt;&lt;endl;
            }
        else{
            while(!read.eof())
            {
                read.getline(newAnimal[i].name, NAME_SIZE, '\n');
                read.getline(newAnimal[i].breed, BREED_SIZE, '\n');
                read.getline(newAnimal[i].desc, DESC_SIZE, '\n');
                read.getline(newAnimal[i].reason, REASON_SIZE, '\n');
                read.ignore(100, '\n');
                read &gt;&gt; newAnimal[i].age;
                read &gt;&gt; newAnimal[i].weight;
                read &gt;&gt; newAnimal[i].day;
                read &gt;&gt; newAnimal[i].month;
                read &gt;&gt; newAnimal[i].year;
                read &gt;&gt; newAnimal[i].length;
                read.ignore(100, '\n');
            }
        }
        read.close();
    }
}


/*
ENROLL FUNCTION
*/

void petAdoption::enroll(animal newAnimal[], int &amp; count)
{
//making a write variable
    ofstream write;

//stores the name into the struct member
    cout &lt;&lt; "Please enter a name: ";
    cin.get(newAnimal[count].name, NAME_SIZE, '\n');
    cin.ignore(100, '\n');
    cout &lt;&lt; "Please enter a breed: ";
    cin.get(newAnimal[count].breed, BREED_SIZE, '\n');
    cin.ignore(100, '\n');
    cout &lt;&lt; "Please enter a desc: ";
    cin.get(newAnimal[count].desc, DESC_SIZE, '\n');
    cin.ignore(100, '\n');
    cout &lt;&lt; "Please enter a reason (EG: eats people): ";
    cin.get(newAnimal[count].reason, REASON_SIZE, '\n');
    cin.ignore(100, '\n');
    cout &lt;&lt; "Please enter an age (EG: 5): ";
    cin &gt;&gt; newAnimal[count].age;
    cin.ignore(100, '\n');
    cout &lt;&lt; "Please enter a weight (in LBS): ";
    cin &gt;&gt; newAnimal[count].weight;
    cin.ignore(100, '\n');
    cout &lt;&lt; "Please enter a day (EG: 2): ";
    cin &gt;&gt; newAnimal[count].day;
    cout &lt;&lt; "Please enter a month (EG: 11): ";
    cin &gt;&gt; newAnimal[count].month;
    cout &lt;&lt; "Please enter a year (EG: 2002): ";
    cin &gt;&gt; newAnimal[count].year;
    cout &lt;&lt; "How long has the pet been in a shelter? (in months): ";
    cin &gt;&gt; newAnimal[count].length;


//error
    if(!write)
    {
        cout &lt;&lt; "Invalid File" &lt;&lt; endl;
    }
    else{
        write.open(newAnimal[count].name, ios::app);    
        write &lt;&lt; newAnimal[count].name &lt;&lt; '\n'
        &lt;&lt; newAnimal[count].breed &lt;&lt; '\n'
        &lt;&lt; newAnimal[count].desc &lt;&lt; '\n'
        &lt;&lt; newAnimal[count].reason &lt;&lt; '\n'
        &lt;&lt; newAnimal[count].age &lt;&lt; '\n'
        &lt;&lt; newAnimal[count].weight &lt;&lt; '\n'
        &lt;&lt; newAnimal[count].day &lt;&lt; '\n'
        &lt;&lt; newAnimal[count].month &lt;&lt; '\n'
        &lt;&lt; newAnimal[count].year &lt;&lt; '\n'
        &lt;&lt; newAnimal[count].length &lt;&lt; '\n';
        write.close();
    }
    if(!write) 
    {
        cout &lt;&lt; "Invalid File";
    }
    else {
        write.open("pets.txt", ios::app);
        write &lt;&lt; newAnimal[count].name &lt;&lt; '\n';
        write.close();  
    }               
}
</code></pre>
