Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <windows.h>
- #include <process.h> // needed for _beginthread()
- struct sourcendest{
- char * source;
- char * destination;
- };
- void testfunc( void * arg ); // function prototype
- void testfunc2( void * sd1 );
- int main(){
- // Our program's first thread starts in the main() function.
- printf( "Now in the main() function.\n" );
- // Let's now create our second thread and ask it to start
- // in the testfunc() function.
- _beginthread( testfunc, 0, (void*)12 );
- // From here on there are two separate threads executing
- // our one program.
- // This main thread can call the testfunc() function if it wants to.
- testfunc( (void*)-5 );
- char c1[50] = "All heil Megatron!\0";
- char c2[50] = "Black patryvan is coming for you!\0";
- char c3[50] = "\0";
- char c4[50] = "\0";
- sourcendest * sd01, * sd02;
- sd01 = new sourcendest;
- sd02 = new sourcendest;
- sd01->source = c1;
- sd02->source = c2;
- sd01->destination = c3;
- sd02->destination = c4;
- printf("c1 = '%s'\nc2 = '%s'\nc3 = '%s'\nc4 = '%s'\n\n", c1,c2,c3,c4);
- testfunc2(sd01);
- _beginthread( testfunc2, 0, (void*)sd02 );
- Sleep( 1000 );
- printf("c1 = '%s'\nc2 = '%s'\nc3 = '%s'\nc4 = '%s'\n\n", c1,c2,c3,c4);
- }
- void testfunc( void * arg){
- printf( "The testfunc() function was passed %d\n", (INT_PTR)arg ) ;
- }
- void testfunc2( void * sd1 ){
- sourcendest * lsd1 = (sourcendest *) sd1;
- unsigned int i = 0;
- for (; lsd1->source[i] > 0; ++i){
- lsd1->destination[i]=lsd1->source[i];
- }
- lsd1->destination[i]=0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement