anonymous_john Posted March 13, 2017 Share Posted March 13, 2017 Hello! Ηow to create a program in C ++ where it counts how many times appears a specific word in a txt file? Can someone help me? Link to comment Share on other sites More sharing options...
0 Dick Montage Posted March 13, 2017 Share Posted March 13, 2017 Sounds like homework? Link to comment Share on other sites More sharing options...
0 dipsylalapo Supervisor Posted March 13, 2017 Supervisor Share Posted March 13, 2017 Why would you need a program to complete it? Surely the CTRL+F and Count would work better in Notepad++ Edit: or what @Nefarious Triggertrigger said Link to comment Share on other sites More sharing options...
0 anonymous_john Posted March 13, 2017 Author Share Posted March 13, 2017 Nefarious Trigger its a project but i have no idea what to do Link to comment Share on other sites More sharing options...
0 Marshall Veteran Posted March 13, 2017 Veteran Share Posted March 13, 2017 2 minutes ago, fifikaki said: Nefarious Trigger its a project but i have no idea what to do A school project? Neowin won't do your homework for you, but we can offer you guidance and point you in the right direction. Eric 1 Share Link to comment Share on other sites More sharing options...
0 anonymous_john Posted March 13, 2017 Author Share Posted March 13, 2017 I want to give me just an idea. Νot solve my project...maybe my question it was wrong. sorry Link to comment Share on other sites More sharing options...
0 Nick H. Supervisor Posted March 13, 2017 Supervisor Share Posted March 13, 2017 Just now, fifikaki said: I want to give me just an idea. Νot solve my project...maybe my question it was wrong. sorry I always started with pseudocode before going in to real coding. That way I had an idea of what I wanted to achieve. So let's start with that, what do you want the program to do? If you had to do the job yourself rather than creating a program, how would you count how many times a certain word appears? Seahorsepip 1 Share Link to comment Share on other sites More sharing options...
0 Dick Montage Posted March 13, 2017 Share Posted March 13, 2017 7 minutes ago, fifikaki said: I want to give me just an idea. Νot solve my project...maybe my question it was wrong. sorry So what self-driven learning have you undertaken so far? I ask this because what you're asking is ridiculously easy, and I struggle to accept that you've even tried so far. Link to comment Share on other sites More sharing options...
0 winlonghorn Posted March 13, 2017 Share Posted March 13, 2017 I would suggest Regular Expressions. Research MatchCollections with Regular Expressions in .NET. That should allow you to achieve what you want. Hopefully, that points you in the right direction. Link to comment Share on other sites More sharing options...
0 Andre S. Veteran Posted March 13, 2017 Veteran Share Posted March 13, 2017 3 hours ago, anonymous_john said: Hello! Ηow to create a program in C ++ where it counts how many times appears a specific word in a txt file? Can someone help me? The problem with a question like this is we have no idea what's actually blocking you. Have you ever written any C++? Any program in any language? Do you know how to open a file in C++? Do you know how to compare strings? Show us what you've done and what exactly is blocking you from making progress. Dick Montage 1 Share Link to comment Share on other sites More sharing options...
0 Seahorsepip Veteran Posted March 14, 2017 Veteran Share Posted March 14, 2017 14 hours ago, winlonghorn said: I would suggest Regular Expressions. Research MatchCollections with Regular Expressions in .NET. That should allow you to achieve what you want. Hopefully, that points you in the right direction. Yes regex is the solution, if you ever need to parse xml I highly suggest using regex But seriously, don't parse xml with regex, if you want to spend a whole summer debugging code go for it but I wouldn't recommend it, regex isn't designed to work well with nested tags neither is it made to do everything text related even when it could be done with a simpel for loop. Regex is useful as example if you don't want to search for just a word but for all words that start with neo and end with win. He asked about c++ that's quite a bit different from .NET and all of it's libraries available for it. .NET is like walking with 2 legs but c++ is not even like walking with 1 leg, it's more like having no legs at all in my experience Link to comment Share on other sites More sharing options...
0 winlonghorn Posted March 14, 2017 Share Posted March 14, 2017 (edited) 7 hours ago, Seahorsepip said: Yes regex is the solution, if you ever need to parse xml I highly suggest using regex But seriously, don't parse xml with regex, if you want to spend a whole summer debugging code go for it but I wouldn't recommend it, regex isn't designed to work well with nested tags neither is it made to do everything text related even when it could be done with a simpel for loop. Regex is useful as example if you don't want to search for just a word but for all words that start with neo and end with win. He asked about c++ that's quite a bit different from .NET and all of it's libraries available for it. .NET is like walking with 2 legs but c++ is not even like walking with 1 leg, it's more like having no legs at all in my experience Sorry, I was reading in a hurry yesterday. I was trying to help out and work on a project for work at the same time. Probably wasn't the best idea. Thank you for your response! I agree about c++ btw. It can be rough! Link to comment Share on other sites More sharing options...
Question
anonymous_john
Hello! Ηow to create a program in C ++ where it counts how many times appears a specific word in a txt file? Can someone help me?
Link to comment
Share on other sites
11 answers to this question
Recommended Posts