Thread: Another searching problem

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    133

    Another searching problem

    Hey guys, I am making a program that reads in simple source code from a text file and counts the integers but I am having a problem that if the int is declared as int hint; it will count that as 2 ints I was told to check and make sure that any presence of 'int' doesn't have alphabetic
    characters surrounding it by and knowing the position of 'int', you just look at the characters before and after those three.

    Although I am using the code if(strcmp(test,"int") == 0) but this code I am currently using but its doesn't tell me the position of int is there away round this problem?

    Thanks.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    instead of starting a new thread you should post here.

    one problem is there are way too many special cases where you'd encounter 'int' in source code where one isn't being declared. and what about this:

    int a, b = foo(n,bar(x)), j = 0;

    now you'll have to figure a way to somehow 'jump' over expressions. the only real solution is to parse the text in a similar manner as a compiler does.
    Last edited by Sebastiani; 02-18-2006 at 07:58 PM. Reason: tag formatting, etc.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Why do you think that searching for characters on either side of a string will be easier than searching for whitespace on either side of a string?

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    133
    I know about the other difficulties that I could face but this program just has to be designed to detect ints in very simple source code, the whitespace problem I was able to solve by going through the array and finding the whitespace using the getline function but as here I am using the strstr function that will not work and if I use the strcmp function it will miss out if there are multiple occurances on one line such as int j; int k;

    Any advice on how i could over come the problem?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical errors with seach function
    By Taka in forum C Programming
    Replies: 4
    Last Post: 09-18-2006, 05:20 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Problem with destructors.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 06-11-2004, 12:30 PM
  4. Replies: 5
    Last Post: 12-03-2003, 05:47 PM