         //cudaMemcpy(str_in_cuda, str_in, size, cudaMemcpyHostToDevice);
         checkCuda(cudaMemcpy(str_in_cuda, str_in, size, cudaMemcpyHostToDevice));
 
-        // TODO: kernel call - save all encoded files to array elements
+        // kernel call - save all encoded files to array elements
         // run function on GPU <<<blocks, no_of_threads>>>
 
-        Encode << < 1, PARTITIONS >>>(size, str_in_cuda, str_out_cuda, sizes_cuda);
+        EncodeCUDA << < 1, PARTITIONS >>>(size, str_in_cuda, str_out_cuda, sizes_cuda);
 
         // TODO: copy back to RAM from GPU
         //cudaMemcpy(str_out, str_out_cuda, PARTITIONS * sizeof (char*), cudaMemcpyDeviceToHost);
+        checkCuda(cudaMemcpy(str_out, str_out_cuda, size, cudaMemcpyDeviceToHost));
         //TODO: :cudaErrorInvalidValue Error Code : 11
-        //checkCuda(cudaMemcpy(str_out, str_out_cuda, PARTITIONS * sizeof(char*), cudaMemcpyDeviceToHost));
-
-        for (i = 0; i < PARTITIONS; i++) {
+
+        /*for (i = 0; i < PARTITIONS; i++) {
             //cudaMemcpy(str_out, str_out_cuda, (size / PARTITIONS + size % PARTITIONS) * sizeof (char), cudaMemcpyDeviceToHost);
             checkCuda(cudaMemcpy(str_out, str_out_cuda, (size/PARTITIONS + size%PARTITIONS)*sizeof(char), cudaMemcpyDeviceToHost));
+        }*/
+        
+        cudaMemcpy(sizes, sizes_cuda, sizeof(int)*PARTITIONS, cudaMemcpyDeviceToHost);
+        //checkCuda(cudaMemcpy(sizes, sizes_cuda, sizeof(int)*PARTITIONS, cudaMemcpyDeviceToHost));
+
+        // file write
+        for (i = 0; i < PARTITIONS; i++) {
+            //printf("part %d - %d\n", i, sizes[i]);
+            char fileName[strlen(s)+5];
+            // creating file names
+            sprintf(fileName, "%s.%d", s, i);
+            //printf("%s\n", fileName);
+            FILE * out = fopen(fileName, "wb");
+            //s[strlen(s) - 2] = '\0';
+
+            // write encoded
+            int offset = (size/PARTITIONS) * i;
+            writeFile(out, i, sizes, str_out, offset);
         }
-        cudaMemcpy(sizes, sizes_cuda, sizeof (int)*PARTITIONS, cudaMemcpyDeviceToHost);
-        //checkCuda(cudaMemcpy(sizes, sizes_cuda, sizeof(int)*PARTITIONS, cudaMemcpyDeviceToHost));
-
-        // TODO: file write
-        for (i = 0; i < PARTITIONS; i++) {
-            printf("part %d - %d\n", i, sizes[i]);
-            // file names
-            sprintf(s, "%s.%d", s, i);
-            FILE * out = fopen(s, "wb");
-            s[strlen(s) - 2] = '\0';
-
-            // write encoded
-            //int offset = size/PARTITIONS * i;
-            //writeFile(out, i, sizes, str_out, );
-        }
 
         /*
-        // fork
-        pid_t pids[PARTITIONS];
-        for(part = 0; part < PARTITIONS; part++){
-        	int pid =fork();
-        	if(pid > 0) {
-            	pids[part] = pid;
-            	continue;
-        	} else {        
-            	//Encode(seeksize+(part==PARTITIONS ? size%PARTITIONS:0), part, size/PARTITIONS * part, str_in, str_out, sizes);        
-        
-        		// file names
-                                sprintf(s,"%s.%d",s,part);
-                                FILE * out = fopen(s, "wb");
-                                s[strlen(s)-2] = '\0';
-        
-        // write encoded
-                                writeFile(out, part, sizes, str_out);
-                                return EXIT_SUCCESS;
-                        }
-                }
-                for(part = 0; part < PARTITIONS; part++) {
-                        if(pids[part] > 0) {
-                                printf("\n\nWaiting on part: %d\n\n", part);
-                                waitpid(pids[part], NULL, 0);
-                        }
-                }*/
-
-        /*
-                     time_t end = time(NULL);// - start;
-                     printf("\nEnd time: %ld\n", end);
-                     printf("\nTime taken: %f\n",difftime(end, start));
-		*/
+        time_t end = time(NULL); // - start;
+        printf("\nEnd time: %ld\n", end);
+        printf("\nTime taken: %f\n",difftime(end, start));
+		    */
     } else {
         // Decode
         int part = 0;

		PC-VAN		SCIENCE
		NIFTY-Serve	PAF01022
		CompuServe	74050,1022
**************************************************************/
#include <stdio.h>
#include <stdlib.h>


#define PARTITIONS 8

FILE	*infile, *outfile;  /* input & output files */

struct stat st; /* to get file size */
