Thread: compare string with time

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    136

    compare string with time

    hi all
    char *str="munna";
    how can i compare srting with time(only with seconds);
    if the str is more than 28 seconds it has to show str1
    char *str1="dude";

    please help me.
    thank you in advance

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    Maybe post a more realistic example of what you're trying to do.

    I've no idea how you compare "munna" to 28 seconds.

    Is it how long you spent thinking about your post?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    136

    thank you for quick replay

    Quote Originally Posted by Salem View Post
    Maybe post a more realistic example of what you're trying to do.

    I've no idea how you compare "munna" to 28 seconds.

    Is it how long you spent thinking about your post?
    is there any way
    Code:
    if(strcmp(str,"munna")>="28 seconds");
    {
    printf("hi");
    else
    {
    printf("bye");
    }
    i dont know how to do. but am thinking of way to do like this.

    any help
    thank you in advance

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    > if(strcmp(str,"munna")>="28 seconds");
    This is not any more realistic based on what you've told us, which is practically nothing.

    > but am thinking of way to do like this.
    You can't. Sorry.

    Where did 28 seconds come from? Why is it significant?
    What you are really trying to do is also painfully obscure.

  5. #5
    Math wizard
    Join Date
    Dec 2006
    Location
    USA
    Posts
    582
    You would first have to compare the numerical value of seconds, not the string. It can be done with strings, but the method is much more complicated. Also, for seconds, are you referring to the clock() function? I'm not sure what you're trying to do, but I'm assuming you want a basic clock and if it reaches 28 seconds, a string appears.

    Code:
    float SecondsStart; // the start time, set only once
    float SecondsEnd; // the end time
    float Seconds; // elapsed time
    
    // have this set once (not in a loop) within some function
    SecondsStart = clock()/CLOCKS_PER_SEC; // have this set once (not in a loop)
    SecondsEnd = SecondsStart; // gives time
    Seconds = SecondsEnd-SecondsStart; // difference in time, use this to compare with
    
    // have this in a loop
    SecondsEnd = clock()/CLOCKS_PER_SEC; // advances the end time
    Seconds = SecondsEnd - SecondsStart; // the difference increments by 1/64 second
    
    Have this code for your string displays as needed (adjust the strings of course)
    if (Seconds >= 28) // if elapsed time is greater than or equal to 28
    {
    	printf("Insert the string you want if the time elapsed is at least your target.");
    }
    
    else
    {
    	printf("Insert the string for the case if below your target time has elapsed.";
    }
    This is the basic timer system, precise to about 1/64 second from the numerous experiments I've done involving it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  2. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  3. String Compare Using Dynamic Arrays
    By djwicks in forum C Programming
    Replies: 4
    Last Post: 03-31-2005, 08:01 PM
  4. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM
  5. How to decrease a time string by a given value
    By Ruchikar in forum C Programming
    Replies: 3
    Last Post: 04-11-2002, 12:08 PM