Can someone please find the error in this. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can someone please find the error in this.

https://code.sololearn.com/c1RIap2qSqLm/?ref=app I have a txt file named file in my desktop but the output is not able to find the number of this and these. I have to submit this code tomorrow, please help me.

20th Nov 2019, 2:09 PM
riya
riya - avatar
2 Answers
+ 1
This appears to be written for an old compiler, so I could not test it in perfect detail, but what I was able to spot: 1. The file name should be given as a string, i.e. ifstream fin( "file.txt" ); 2. You used cout without including iostream. 3. Both c and d are unused variables. 4. In the second if-statement, you use the assignment operator instead of the comparison operator. 5. Strings like "this" and "these" should be enclosed in double quotation marks, not single quotation marks. 6. You try to compare ch with "this" and "these", but this is actually pointer comparison, not string comparison -> undefined behaviour. Either use https://en.cppreference.com/w/c/string/byte/strcmp for exact comparison or https://en.cppreference.com/w/c/string/byte/strstr if e.g. "xxxthisxxx" also counts as a valid appearance, or use modern C++ strings in the first place. As an example, here is a program showing how it could be done, not sure of how much use it is to you: https://code.sololearn.com/cI8OXhO22ZdA/?ref=app
20th Nov 2019, 5:43 PM
Shadow
Shadow - avatar
0
Shadow Thank you so much for taking out your time to tell me where I went wrong ( ^ω^)
20th Nov 2019, 5:54 PM
riya
riya - avatar