I wrote this code. in this program i read a file then pour part of file into the char* temp. Finally char *temp written in the file.I have a problem. When i write temp in file only 4 character written in it.What do i do?
fstream file;
file.open("mary.txt",ios::in);
file.seekg(-1,ios::end);
int pos=file.tellg();
char ch;
char c;
int i=0;
char * temp=new char[100];
file.seekg(0,ios::beg);
while(pos >=0)
{
file.read(&ch,sizeof(char));
if(ch=='a'||ch=='o'||ch=='u'||ch=='e'||ch=='i'||ch=='A'||ch=='O'||ch=='U'||ch=='E'||ch=='I')
{
pos--;
continue;
}
else if(ch>='a' && ch<='z')
{
c=ch-32;
temp[i]=c;
i++;
}
else
{
temp[i]=ch;
i++;
}
pos--;
}
temp[i]=NULL;
cout<<temp<<endl;
cout<<" sizeof temp:"<<sizeof(temp)<<endl;//out put is 4 while temp has longer size!! why?
fstream f("test.txt",ios::trunc);
f.write(temp,sizeof(temp));//if the file contains "abcdeifjle" only written "abcd"