Thread: Expression preceding parethenses?

  1. #16
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    992
    Quote Originally Posted by nothing909 View Post
    do i need to write a delay function for the delay to work?
    if so, how do i go about writing it? can you give me an example
    Why not just use the standard sleep() function if your compiler has it. It would do the same thing.

  2. #17
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    Quote Originally Posted by userxbw View Post
    that is just a blank loop that just loops for an x amount of time to make a delay occur, give it a try, the larger the number the longer the delay. the need to make his or her code into a function is up to the programmer.
    Code:
    void AI(void){
        unsigned int delay = 1000;
    
    
      if (yR2 > yBall)
      {
       if (yR2 > RACKET ) 
       {
           delay(1000);
        yR2--; 
       }
    
      }
    


    i'm honestly so confused why this code isn't working and i'm receiving this error. what is the problem with it, i've been trying to work it out for hours.

  3. #18
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    Quote Originally Posted by rstanley View Post
    Why not just use the standard sleep() function if your compiler has it. It would do the same thing.

    could you please explain, relating it to my code, how i can use a sleep function. i don't know if this is correct, but if i do:

    Code:
    void AI(void){
        unsigned int sleep = 1000;
     
     
      if (yR2 > yBall)
      {
       if (yR2 > RACKET ) 
       {
           sleep(1000);
        yR2--; 
       }
     
      }
    Code:
    
    
    that still gives me the exact same error.

  4. #19
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Code:
    #include <unistd.h>
           
    int main(int argc, const char **argv)
    {
        if ( argc < 2)
        {
            printf("no input\n"
            "Input a number to se if odd or even\n");
            return -1;
        }
        
        sleep(10);
         printf("I just slept for 10 seconds\n");
    return 0;
    }
    as far as errors to this code,
    Code:
    void AI(void){
        unsigned int delay = 1000;
     
     
      if (yR2 > yBall)
      {
       if (yR2 > RACKET ) 
       {
           delay(1000);  
        yR2--; 
    
       }
     
      }
    me as well as others are going to need to see more then just that to see what errors you're talking about.

    -- besides this. what function is called delay, and why you making a variable called delay then using a function called delay then putting in the same amount of your variable called delay into that function by the same name?
    Last edited by userxbw; 12-10-2017 at 03:09 PM.

  5. #20
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    Quote Originally Posted by userxbw View Post
    Code:
    #include <unistd.h>
           
    int main(int argc, const char **argv)
    {
        if ( argc < 2)
        {
            printf("no input\n"
            "Input a number to se if odd or even\n");
            return -1;
        }
        
        sleep(10);
         printf("I just slept for 10 seconds\n");
    return 0;
    }
    i don't think my compiler has the sleep function, it doesn't work.

    could you please look at my first post, with the code i gave and explain the reason why it wouldn't work because i still don't know.

  6. #21
    Banned
    Join Date
    Aug 2017
    Posts
    861
    #include <unistd.h> did you put that in your code?

    Post your entire program, anyone can post a function and ask why is this not working when the function has vars or struct and stuff in the function that are not explained for someone else to know what they are.

    I think someone already asked if they , your variables are global or not.
    Code:
    void AI(void){
        unsigned int delay = 1000;
      
      
      if (yR2 > yBall)
      {
       if (yR2 > RACKET ) 
       {
           delay(1000);  
        yR2--; 
     
       }
    Last edited by userxbw; 12-10-2017 at 03:17 PM.

  7. #22
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    the code i provided is for a pong game, its just delaying the racket movement

  8. #23
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by nothing909 View Post
    the code i provided is for a pong game, its just delaying the racket movement
    secret code, I get it. Ok. do you know what the difference between global and local and protected when it comes to data types and their access to them?
    because if your, yR2, yBall, yR2, RACKET are not global then how will that function see them to determine what they are, and I nor others do not really even know what errors your compiler/program is throwing even. I have not seen that information. if they are not global then you're going to need to pass them into your function.

  9. #24
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    they're all global variables, that isn't the problem

  10. #25
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    992
    Quote Originally Posted by nothing909 View Post

    could you please explain, relating it to my code, how i can use a sleep function. i don't know if this is correct, but if i do:

    Code:
    void AI(void){
        unsigned int sleep = 1000;
     
     
      if (yR2 > yBall)
      {
       if (yR2 > RACKET ) 
       {
           sleep(1000);
        yR2--; 
       }
     
      }
    Code:
    
    
    that still gives me the exact same error.
    Providing you add the following at the top of your .c file or in a header file called by your .c file, it should work. Please read the man page for sleep(). The argument to sleep() is the number of seconds, so 1000 is over 16 minutes! ;^)
    Code:
    #include <unistd.h>

  11. #26
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    Quote Originally Posted by userxbw View Post
    [code]
    -- besides this. what function is called delay, and why you making a variable called delay then using a function called delay then putting in the same amount of your variable called delay into that function by the same name?
    if i remove the unsigned int delay = 1000;

    and i just have delay(1000);

    it now says on the delay(1000) line that delay is being declared implicitly. what does this mean

  12. #27
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    Quote Originally Posted by rstanley View Post
    Providing you add the following at the top of your .c file or in a header file called by your .c file, it should work. Please read the man page for sleep(). The argument to sleep() is the number of seconds, so 1000 is over 16 minutes! ;^)
    Code:
    #include <unistd.h>
    i can't add that "source file cannot be found.

  13. #28
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by nothing909 View Post
    if i remove the unsigned int delay = 1000;

    and i just have delay(1000);

    it now says on the delay(1000) line that delay is being declared implicitly. what does this mean
    that you have a function that does not have it's header included into that file you are using the function in so it has no idea what to do with it. you're missing the header file that has the proto type for the function to it can link it to the object file of the same.
    google says
    Here unsigned int is the number of milliseconds (remember 1 second = 1000 milliseconds). To use delay function in your program you should include the "dos.h" header file which is not a part of standard C library.
    so that tells me it is a DOS (really old media) function, dos.h is where the delay function is located.

    Like others have been showing you, I'd change my implementation to that loop if you cannot get sleep to work. Just expenment to see how long that loop last depending on what number you put into it to get you're 1000 seconds.
    or x * 60 to get minutes. ie 1 * 60 = 1 minute. etc...
    that is using sleep.
    Last edited by userxbw; 12-10-2017 at 03:55 PM.

  14. #29
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    992
    Quote Originally Posted by nothing909 View Post
    i can't add that "source file cannot be found.
    Which "source file" cannot be found??? I am totally confused!

  15. #30
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    i'm so confused, i've never used dos.h before. i thought creating a delay was an easy little thing.

    in my code the way it, can you explain how i can create a simple delay without using delay or sleep, what is it i have to do

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rotation independent of preceding rotations (DirectX)
    By blakeo_x in forum Game Programming
    Replies: 12
    Last Post: 10-03-2012, 05:23 PM
  2. initializer expression list treated as compound expression
    By karthikeyanvisu in forum C Programming
    Replies: 7
    Last Post: 02-26-2011, 05:19 PM
  3. Replies: 2
    Last Post: 11-25-2009, 07:38 AM
  4. preceding zeros in int variables
    By AshFooYoung in forum C Programming
    Replies: 2
    Last Post: 09-23-2001, 02:28 PM
  5. Preceding 0
    By morbuz in forum C++ Programming
    Replies: 2
    Last Post: 09-19-2001, 12:15 PM

Tags for this Thread