Saltar al contenido
Underc0de /foro

Funcion sleep en C en Linux

Iniciado por fRNN, Diciembre 18, 2015, 03:45:06 AM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Avatar de fRNN
Diciembre 18, 2015, 03:45:06 AM Ultima modificación: Enero 03, 2016, 11:05:01 PM por EPSILON

Hola gente! Estoy aprendiendo C y tenia que hacer un cronometro con el bucle for. El tema es que, en windows me anda pero en mi Ubuntu, con Geany compila pero me sale la consola y nada. Cual es mi error?

Código: c

#include <stdio.h>
#include <unistd.h>

int main ()
{
int h, m, s, x;
x = 1000;

for (h=0;h<60;h++) {
for (m=0;m<60;m++) {
for (s=0;s<60;s++) {
printf ("%i:%i:%i\r", h, m, s);
sleep (x);
}
        }
}
}           
WhatsApp Telegram

6 respuestas

Avatar de Stiuvert
Intoduce antes de cerrar el main un getch y return.

Código: c
} //Cierre del for
} //Cierre del for
} //Cierre del for
getch();
return 0;
} // Cierre del main



Avatar de fRNN
Gracias por responder :) pero me sale esto en consola que sera ?

./geany_run_script.sh: 5: ./geany_run_script.sh: ./bucles anidados: not found


------------------
(program exited with code: 127)
Press return to continue

Avatar de rush
You only compiled your source file, but didn't build your application, meaning the linking was not done and the executable was not created. Use the "build" sub-menu from the "build" menu (default shortcut is F9 if I recall correctly) and try again.
Los enlaces son solo para miembros. Registrate o iniciá sesión


Avatar de fRNN
Cita de: rush en Diciembre 18, 2015, 08:41:48 PM
You only compiled your source file, but didn't build your application, meaning the linking was not done and the executable was not created. Use the "build" sub-menu from the "build" menu (default shortcut is F9 if I recall correctly) and try again.

Tenias razon. Ya pude compilar sin ningun error. Pero me sigue sin funcionar el programa. Me muestra con el printf, los valores 0:0:0 pero no sigue.. En windows me anda bien.

Gracias de todos modos:)

Avatar de v4char
Diciembre 19, 2015, 01:58:19 AM #5 Ultima modificación: Diciembre 19, 2015, 02:00:04 AM por v4char
Prueba esto
Código: cpp
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

int main ()
{
   int h, m, s, x;
   x = 1;

   for (h=0;h<60;h++)
   {
      for (m=0;m<60;m++)
      {
         for (s=0;s<60;s++)
         {
            printf ("%i:%i:%i\n", h, m, s);
            sleep (x);
         }
       }
    }
}


Se compila con "gcc archivo.c" y se ejecuta con "./a.out" (supongo que ya lo sabrás)

Avatar de fRNN
Cita de: v4char en Diciembre 19, 2015, 01:58:19 AM
Prueba esto
Código: cpp
#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

int main ()
{
   int h, m, s, x;
   x = 1;

   for (h=0;h<60;h++)
   {
      for (m=0;m<60;m++)
      {
         for (s=0;s<60;s++)
         {
            printf ("%i:%i:%i\n", h, m, s);
            sleep (x);
         }
       }
    }
}


Se compila con "gcc archivo.c" y se ejecuta con "./a.out" (supongo que ya lo sabrás)
Ahi esta ahora si me anda gracias. Con el \n en el printf. Porque no funciona el \r ?

¿Te quedó una duda sobre Dudas y pedidos generales?

Preguntala y te responde la comunidad (y el asistente Underc0de IA si nadie llega antes). Es gratis y tarda un minuto.

Ya tengo cuenta
Guardamos tu pregunta en este navegador: después de entrar la publicás con un clic.
Grupo de WhatsApp