Hey guys, I now want to make a program to count simple integers my first problem is that the following code will also count the word hint as an int. I was wondering if there is an easy way round this problem? (I tried putting whitespace after the word like "test " although that didn't work either)

I am aware of the other problems when counting ints such as if one is declared like int j,k,l; and int functions but I can solve the int j,k,l; with a loop although im not sure about the int functions.

char array [200];
ifstream file;

      while (file >> array)
	   {
			if(strstr(array,"test") != 0)
                        test++;
           }

write a function to test the string to see if it contains only numeric digits. Fucntion should return true if the string contains only numeric digits or false otherwise.

Sorry I dont' understand how that helps if an int is being counted in the word hint appears in the text file?

Probably me being silly.

I thought you meant that the text file contains a mixture of words and integers, and you wanted to count the number of integers in the file. If that is not the case, then you need to post an example of the text file and a better (more detailed) explaination of what you want to do with it.

Hi sorry if I wasn't being clear, I am trying to create a program that will count integers from simple source code stored in a text file the code I posed above does this by counting the words that have int in them. The problem is that if there is a word such as hint appeared in the text file as it contains int it wil also be counted as an integer so I was just wondering if there was a way round this problem? Thanks.

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.