Thread: Problem with comparison

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    4

    Problem with comparison

    Code:
    #include <stdio.h> 
    #include <time.h> 
    
    char ime[4] = "Thu";
    int main ( void )
    {
      time_t now;
      struct tm *tm_now;
      char buff[BUFSIZ];
    
      now = time ( NULL );
      tm_now = localtime ( &now );
    
      strftime ( buff, sizeof buff, "%a", tm_now );
      printf ( "%s\n", buff );
    
      if (buff == ime)
      printf ("bravo");
      else
      printf ("TUBL");
    
      return 0;
    }
    Why do I allways get "TUBL" response, even if "buff" and "ime" are the same ???

    Buff prints out day of the week - Thu, Wed, Fri...

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    operator== works on string objects, but for C-strings you must use strcmp in string.h

    Also, this should have gone in the C forum. Sorry.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Looks like you are doing pointer comparison when you want to compare strings. Use strcmp() instead.

    By the way, perhaps this is better placed in the C forum since you are asking for help with a C program?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Moved.
    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.

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    4
    My next problem

    Code:
    Code:
    #include <stdio.h>
    #include <time.h>
    #include <string.h>
    
    int main ( void )
    {
    
    while(1)
    {
    
      time_t start_time, cur_time;
    
             time(&start_time);
             do
             {
                     time(&cur_time);
             }
             while((cur_time - start_time) < 1);
    
      time_t now;
      struct tm *tm_now;
      char buff1[BUFSIZ]; // PING
      char buff2[BUFSIZ]; // MAIL
      now = time ( NULL );
      tm_now = localtime ( &now );
    
      strftime ( buff1, sizeof buff1, "%X", tm_now ); //PING
      strftime ( buff2, sizeof buff1, "%w%X", tm_now ); //MAIL
      printf ("%s\n",buff1);
      printf ("%s\n\n",buff2);
      if( strcmp( buff1, "11:26:40" ) == 0 )
         system("./php Command_line.php ");
    
    if( strcmp( buff2, "412:08:20" ) == 0 )
         system("./php posiljanje_na_gmail_za_probo.php ");
    
    //  return 0;
    
    
      }
      }
    I've got time working now (delay for 1 sec, and run the program at preset time).

    My problem now is, that when I run Command_line.php, the php program (ping about 5000 computers) works for about an hour, but then does not continue with my c program.
    I want my c program, to continue working after the php program is finished.
    What can I do?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM