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.

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);
}
        }
}
}           

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



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

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.
No tienes permitido ver los links. Registrarse o Entrar a mi cuenta


No tienes permitido ver los links. Registrarse o Entrar a mi cuenta
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:)

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)

No tienes permitido ver los links. Registrarse o Entrar a mi cuenta
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 ?