Underc0de - La Casa de los Informáticos

Foros Generales => Dudas y pedidos generales => Mensaje iniciado por: fRNN en Diciembre 18, 2015, 03:45:06 AM

Título: Funcion sleep en C en Linux
Publicado por: fRNN en Diciembre 18, 2015, 03:45:06 AM
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?


#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);
}
        }
}
}           
Título: Re:Funcion sleep en C en Linux
Publicado por: Stiuvert en Diciembre 18, 2015, 05:33:39 AM
Intoduce antes de cerrar el main un getch y return.

} //Cierre del for
} //Cierre del for
} //Cierre del for
getch();
return 0;
} // Cierre del main


Título: Re:Funcion sleep en C en Linux
Publicado por: fRNN en Diciembre 18, 2015, 07:39:44 PM
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
Título: Re:Funcion sleep en C en Linux
Publicado por: 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.
Título: Re:Funcion sleep en C en Linux
Publicado por: fRNN en Diciembre 18, 2015, 09:45:26 PM
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
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:)
Título: Re:Funcion sleep en C en Linux
Publicado por: v4char en Diciembre 19, 2015, 01:58:19 AM
Prueba esto
Código (cpp) [Seleccionar]
#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)
Título: Re:Funcion sleep en C en Linux
Publicado por: fRNN en Diciembre 21, 2015, 05:54:21 AM
You are not allowed to view links. You are not allowed to view links. Register or Login or You are not allowed to view links. Register or Login
Prueba esto
Código (cpp) [Seleccionar]
#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 ?