Can somebody show me how to search and count for the string. If i have a set of data,i.e.

"0012", "0034", "0055"' "0099"
"0013", "0032", "0012","0099"

let's say i chose the 1st string(at the 1st line),"0012", and based on this string, i would like to search and count that string at the 2nd line.

My intention is to search and count that string from the different line.:rolleyes:

what do you want to search for and what do you want to count? do you want to count the number of times "0012" appears in both lines (and the same for each of the other strings on line 1) ?

one way to do it is to create a structure that contains the word to search for and an integer that is the number of times that word appears in the other lines

struct count
{
    char word[20];
    int counter;
}

create and populate an array of those stuctures from the words in the first line, then read the second line and search each of the structures for the word. When found increment its counter, then go on to the next word in the second line. continue that until all the words have been read from the file. When finished, you will have a total frequency count for each word.

Look into the strstr() function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.