954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Another counting problem

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++;
           }
Jon182
Junior Poster in Training
91 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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.

Jon182
Junior Poster in Training
91 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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.

Jon182
Junior Poster in Training
91 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You