I am using this function usleep() which is suppose to stop any operation for several seconds. Any way I get this error while trying to compile my code
stream.c:28:4: error: implicit declaration of function 'usleep' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
I know that this means that I should include the library which contains this function and I read about in the GNU manual and double checked the library that contains this function and "included" the library in my code. Still I get the same error.In addition I installed the unistd.h on my system. Any ideas why might that be happening ?
here is my code (usleep is in the forloop)
// standard libraries
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
//mpg library
#include "mpg.h"
// main function
int main(void)
{
FILE* media = fopen("live.mp3", "r");
if(media == NULL)
{
printf("Couldn't read file\n");
return -1;
}
MPEGTAG2* mp3_tag = malloc(sizeof(mp3_tag));
mp3Header(media, mp3_tag);
while(feof(media) == 0)
{
int ms;
int nbits;
frameInfo(media, &ms, &nbits);
size_t nbytes = nbits / 8;
int rate = ms / nbytes;
for(int i = 0; i < nbytes; i++)
{
printf("%d seconds\n", rate);
usleep(rate);
}
fseek(media, nbytes, SEEK_CUR);
}
free(mp3_tag);
}
usleep()
is obsolete. You shouldn't use it! Usenanosleep()
instead.