Problem with comparison

This is a discussion on Problem with comparison within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <time.h> char ime[4] = "Thu"; int main ( void ) { time_t now; struct tm *tm_now; ...

  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
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,627
    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
    21,410
    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?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,437
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 10: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, 04:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21