Computing.Net > Forums > Programming > counting occurences of a keyword

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

counting occurences of a keyword

Reply to Message Icon

Name: Infinite Recursion
Date: March 5, 2004 at 06:19:57 Pacific
OS: na
CPU/Ram: na
Comment:

does anyone know of a function that will allow me to count the occurences of a keyword in a text file? im trying to count the number of calls to strlcpy that i am making in my c code.

thanks.

gunther



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: March 5, 2004 at 09:53:14 Pacific
Reply:

You don't mention your OS.

In UNIX/Linux, you can use grep and wc to count occurrences

cat myprog.c | grep strlcpy | wc -l


The above command will tell you how many lines in myprog.c contain the string 'strlcpy'. Note, that isn't necessarily the same thing as the number of occurrences of 'strlcpy' (more than one occurrence on a line?)


0

Response Number 2
Name: wizard-fred
Date: March 5, 2004 at 17:06:12 Pacific
Reply:

Some word processors and text editors have a count function. Some might be part of the search/replace function.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


avoiding buffer overflows... some questions



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: counting occurences of a keyword

Batch file: Count instances of a word www.computing.net/answers/programming/batch-file-count-instances-of-a-word/19684.html

File I/O counting number of words in a file www.computing.net/answers/programming/file-io-counting-number-of-words-in-a-file/20183.html

Count comma in each line of a text www.computing.net/answers/programming/count-comma-in-each-line-of-a-text-/17747.html