简体   繁体   中英

Implicit declaration of function 'delay' in C

I really can't understand what is wrong with my code. My teacher said to add time.h and process.h but still doesn't work. I am using TDM-GCC-64 . Code :

#include <conio.h>
#include <string.h>
#include <process.h>
#include <time.h>
int main()
{
  char str[30];
  int i;
  printf("Enter the string: ");
  scanf("%s",str);
  for(i=0;str[i]!='\0';i++)
  {
    printf("%c",str[i]);
    delay(1000);
  }
  return 0;
}

There is no delay function. You should use sleep instead.

So instead of

delay(1000);

do

 sleep(1); // sleep 1 second

Don't forget to include <unistd.h>

If you need the delay function you need to write it yourself. For example the blocking version:

void delay(unsigned milliseconds)
{
    clock_t pause;
    clock_t start;

    pause = milliseconds * (CLOCKS_PER_SEC / 1000);
    start = clock();
    while( (clock() - start) < pause );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM