0
Error in source code
Can anyone plz elaborate why my proram is ending with giving a msgs that it has abortedđ„ș https://code.sololearn.com/cG3hIJSnR4UB/?ref=app
9 Respostas
+ 3
Thanks a bunch XXX for the correction đ
That was actually what I meant. Looking at it now, I don't even know what was going on that I did it twice.
Iffat,
Sorry I confused you buddy, made a typo there, twice â
+ 2
Iffat,
I was thinking something like this in main()...
ifstream in("intel.doc");//opening file
if( !in.is_open() ) // file open failed!
{
std::cout << "Unable to open file!\n";
return -1; // signal an error
}
// rest of the code ...
(Edited)
+ 2
Ipang
ifstream::open() is used for opening files. I think you meant ifstream::is_open() instead.
```
ifstream in("intel.doc");
if (!in.is_open())
{
...
}
...
```
Iffat
Also, why are you using a char array and strcmp(), when you can just use the std::string type from the <string> header and use the == operator to compare them?
+ 2
Your code seems to work after fixing the problem pointed out by Ipang
https://code.sololearn.com/cYudoWMhGYKW/?ref=app
I suggest you use std::string instead of char array and the == operator instead of strcmp(), like this
https://code.sololearn.com/cwDbz59dOvr9/?ref=app
+ 2
XXX Tysm
+ 1
Iffat,
Check whether the file is opened before doing anything with it.
if( !in.is_open() )
{
// file open failed
}
As it is now, the loop that tries to read the file becomes infinite, as the file open failed ...
(Edited)
+ 1
Ipang can u plz tell exactly what should i do plzzđ„ș?
+ 1
Ipang tysm anyway
0
XXX the output wasn't coming as required,it was giving 0 every timeâčïž