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

8th Dec 2021, 6:08 AM
Brat__
Brat__ - avatar
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 ☝
8th Dec 2021, 6:04 PM
Ipang
+ 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)
8th Dec 2021, 2:29 PM
Ipang
+ 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?
8th Dec 2021, 3:43 PM
XXX
XXX - avatar
+ 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
8th Dec 2021, 4:16 PM
XXX
XXX - avatar
+ 2
XXX Tysm
8th Dec 2021, 11:02 PM
Brat__
Brat__ - avatar
+ 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)
8th Dec 2021, 9:24 AM
Ipang
+ 1
Ipang can u plz tell exactly what should i do plzzđŸ„ș?
8th Dec 2021, 2:20 PM
Brat__
Brat__ - avatar
+ 1
Ipang tysm anyway
8th Dec 2021, 11:02 PM
Brat__
Brat__ - avatar
0
XXX the output wasn't coming as required,it was giving 0 every timeâ˜č
8th Dec 2021, 3:45 PM
Brat__
Brat__ - avatar