Help ! Debug code.

kpsg25690's Avatar, Join Date: Aug 2009
Go4Expert Member
hey guys i made this program but i can't make it work.
it's a program to remove extra spaces from a file.
please help need to get program working by tommorow........

Code:
#include<fstream.h> 
#include<conio.h> 
#include<stdio.h> 
#include<string.h> 
 
void main() 
{ 
clrscr(); 
ifstream fin; 
ofstream fout; 
fstream f1; 
 
char *line,ch,chh; 
int s,f=0; 
fout.open("xyz.txt"); 
cout<<"Enter a line:"; 
gets(line); 
s=strlen(line); 
fout.write(line,s); 
fout.close(); 
fin.open("xyz.txt",ios::beg); 
f1.open("file2.txt",ios::out,ios::in); 
 
while(!fin.eof()) 
{ 
    fin.get(ch); 
    if(ch==' ') 
    { 
        if(f==0) 
            { 
                   f1.put(ch); 
                f=1; 
            } 
 
    } 
    else 
    { 
           f1.put(ch); 
        f=0; 
    } 
} 
 
 
fin.close(); 
cout<<"\nThe contents of the new file are:"; 
f1.seekg(0,ios::beg); 
 
while(!f1.eof()) 
    { 
        f1.get(chh); 
        cout<<chh; 
    } 
 
f1.close(); 
 
 
getche(); 
}


hope to get a reply...
0
kpsg25690's Avatar, Join Date: Aug 2009
Go4Expert Member
take a look at this too
it's a program to sort even and odd numbers and put them into different files..
the output is not what it should be.....

Code:
#include<fstream.h> 
#include<conio.h> 
#include<stdio.h> 
 
void main() 
{ 
clrscr(); 
int n,arr[100],i; 
char j; 
fstream file,file2; 
file.open("even.txt",ios::in|ios::out); 
file2.open("odd.txt",ios::in|ios::out); 
cout<<"\nHow many numbers do you want to enter:"; 
cin>>n; 
for(i=0;i<n;i++) 
{ 
cin>>arr[i]; 
} 
for(i=0;i<n;i++) 
{ 
    if(arr[i]%2==0) 
        { 
         file.put(arr[i]); 
        } 
       else 
       { 
         file2.put(arr[i]); 
       } 
} 
file.put(EOF); 
file2.put(EOF); 
 
file.seekg(0,ios::beg); 
file2.seekg(0,ios::beg); 
cout<<"\nThe contents of the EVEN file are:"; 
while(!file.eof()) 
{ 
file.get(j); 
cout<<i<<"\n"; 
} 
cout<<"\nThe contents of the ODD file are:"; 
while(!file2.eof()) 
{ 
file2.get(j); 
cout<<i<<"\n"; 
} 
file.close(); 
file2.close(); 
getche(); 
}


please help.....
i need these urgently.....