create a program that differentiate between banks

Hello.
I've created this code that differentiate between various uses of banks like for example if the user enters he went to bank to deposit money and then went to the river bank
The output will be finance river
The code is not working correctly please help me.

[ Code ]
#include<fstream.h>
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<string.h>
void main()
{
void checkr();
void checkf();
void checkt();
void conv();
int checkbank();
void delfile();
ofstream fout;
fout.open("input.txt");
char ch[200];//,ch1[200];

int f1=0;
printf("Please enter input text :- \n");
scanf("%s",&ch);
fout<<ch;
fout.close();
conv();
f1=checkbank();
if(f1!=0)
{
checkr();
checkf();
checkt();
delfile();
}
else
cout<<"ERROR !!! no bank word found";
getch();
}
void conv()
{
char ch,ch1;
ptr1=fopen("input.txt","r");
ptr2=fopen("inputlow.txt","w");
ifstream fin;
fin.open("input.txt");
ofstream fout;
fout.open("inputlow.txt");
char ch;
char ch1;
while(!fin.eof())
{
fin.get(ch);
ch1=tolower(ch);
fout<<ch1;
}
fin.close();
fout.close();
}
int checkbank()
{

char ch[20];
int cnt=0;
ifstream fin;
fin.open("input.txt");
char word[30];
int cnt=0;
while(!fin.eof())
{
fin>>word;
if(strcmp(word,"bank")==0)
cnt++;
}
return(cnt);
}

void checkr()
{//check for rivers
ifstream fin;
char ch[20];int g1;
g1=0;
fin.open("inputlow.txt");
while(!fin.eof())
{
fin>>ch;
if(strcmp(ch,"river")==0)
{ g1++;
}
}
if(g1!=0)
cout<<"River"<<"\t";
}
void checkf()
{//check for finance
ifstream fin;
char ch[20];int cnt=0;
fin.open("inputlow.txt");
while(!fin.eof())
{
//fscanf(ptr4,"%s",&ch);
fin>>ch;
if(strcmp(ch,"money")==0)
{
cnt++;
}
}

if(cnt!=0)
{
cout<<"Finance"<<"\t";
}
}
void checkt()
{//check for tilt
ifstream fin;
char ch[20];int g3=0;
fin.open("inputlow.txt");
while(!fin.eof())
{
fin>>ch;
if(strcmp(ch,"road")==0||strcmp(ch,"path")==0||strcmp(ch,"flyover")==0)
{
g3++;
}
}
if(g3!=0)
{
cout<<"Tilt"<<"\t";
}
}
void delfile()
{
remove("input.txt");
remove("inputlow.txt");
}

[/code]
I've got plenty of pointers, but I think you may find the most useful of them to be #1.
1. In function checkbank(), you are using input.txt where all other functions are using inputlow.txt
2. Why are you using files to transfer data? Why not just pass the data among the functions as a string?
3. Where is all the white-space? Have a white-space phobia?
4. In function conv(), ptr1 and ptr2 are not defined anywhere within the scope that you provided. This should not even compile.
5. Function checkr() has char ch[20] that is unused. Not really important, but it is wasted space.
6. Why are your functions defined inside main()? Normally they are defined globally. Ie
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <fstream.h>
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>

void checkr();
void checkf();
void checkt();
void conv();
int checkbank();
void delfile();

void main() {}


Fix #1 and #4, and see how it works...
Topic archived. No new replies allowed.