How can I separate an integer into digits using for loop?
eg.
before: 123
after: 1 2 3
anyone can help me with that?
Here is an idea. Convert to char *
How can I separate an integer into digits using for loop?
eg.
before: 123
after: 1 2 3
anyone can help me with that?
Here is an idea. Convert to char *
A little bug just change the Exit func to
void * Exit(void * ptr)
{
char c;
while (1)
{
scanf("%c", &c);
if ( c == 'e')
breakLoop = 1;
}
}
This is just an idea how can solve your problem
#include "stdio.h"
#include "pthread.h"
pthread_t threadEvent;
unsigned char breakLoop = 0;
void * Exit(void * ptr)
{
char c = 'a';
scanf("%c", &c);
if ( c == 'e')
breakLoop = 1;
}
main()
{
int i = 0;
pthread_attr_t attr;
char * arg = NULL;
pthread_attr_init(&attr);
int threadID;
threadID = pthread_create(&threadEvent, &attr, Exit, arg); // create thread wich recives user input
while(1)
{
printf("%d\n",i++);
if (breakLoop)
break;
sleep(1);
}
return 0;
}
So the logic is that you create a thread wich will take input from user :).
Adopt this code for your compiler. I dont have conio.h so I used scanf instead of getch. But avoid scanf. Modify sleep with usleep. Compiled with gcc.
thankx for your kind reply,
i will try to create file with .cpp extension and try to compile it with the given command i also want to know more about knoppix can you tell me more about programming in knoppix or can you give me reference website which can be useful for me to develope my skill.
On google I found many links (typed KNOPPIX). Use google and find links wich are interesanting to you. For example maybe this link is interesanting
http://www.shockfamily.net/cedric/knoppix/
http://distrowatch.com/table.php?distribution=knoppix.
For programming try to search linux programming on google. Here are some links for compilers
http://www.stat.uchicago.edu/~gosset/Compdocs/gcc.html
http://www.cs.wm.edu/cspages/computing/tutorial/gpp.html
Hope that this help
Use some editor to create example x.cpp.
Then try to compile with g++ -o x x.cpp (without additional library) and run it with ./x command. Type this lines in console. If error occures then use google to check them. I think that knoppix has gcc and g++ included in it.