Thread: strlen in expressions

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    5

    strlen in expressions

    hi i am trying to make a program do this basically...

    int * strlen / strlen * strlen * strlen = an int

    i cannot figure out how to write that in code...

    i don't know if you cannot use strlen in a "formula" ? or what?

    thanks

    mathatmatically

    (5000 * 8) / (5 * 8 * 8)

    obviously using varibles in the program

    thanks again

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Two methods:

    Code:
    int main( void )
    {
    	// USING *STRINGS
    
    	char *C_Str1;
    	char *C_Str2;
    	char *C_Str3;
    	char *C_Str4;
    	
    	// Intitalise the *strings
    
    	std::cout<< (5000*strlen(C_Str1))/(strlen(C_Str2)*strlen(C_Str3)*strlen(C_Str4));
    
    
    
    	// USING STD::STRING
    
    	std::string one;
    	std::string two;
    	std::string three;
    	std::string four;
    
    	// Initalise the std::strings
    	std::cout<< (5000 * one.size()) / (two.size() * three.size() * four.size());
    
    	return 0;
    }
    Or something to that effect.

  3. #3
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Try: x = (a*b)/(c*d*e);

    = is for assignment, you can't assign a value to a mathematical calculation, that's why x that gets the value is on the left.

    Also use brackets to make the statement non-ambigous.

  4. #4
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    justforthis1, in the future could you make your titles a little more informative, for example "strlen in a formula" rather than "dumb newb question".
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    5
    ok thanks, that helps a lot, it works now anyways

    sorry about the title, i will do better next time

    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack that evaluates postfix expressions
    By killmequick in forum C Programming
    Replies: 7
    Last Post: 10-01-2008, 06:23 PM
  2. strlen()
    By BoneXXX in forum C Programming
    Replies: 6
    Last Post: 06-17-2007, 01:32 AM
  3. Regular expressions [Boost]
    By Desolation in forum C++ Programming
    Replies: 8
    Last Post: 12-30-2006, 10:10 PM
  4. strlen()
    By exoeight in forum C Programming
    Replies: 9
    Last Post: 04-01-2005, 10:18 AM
  5. Just say NO to strlen.
    By anonytmouse in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 02-11-2005, 01:34 PM