SHARE
TWEET

Untitled

czlowiekzgon Mar 19th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. void fun(char * s){
  7.   int len;
  8.   len = strlen(s);
  9.   if(len == 0){
  10.     return;
  11.   }
  12.   char * firstS;
  13.   char *secondS;
  14.   char *supS;
  15.  
  16.   if(len % 2 ){
  17.     supS = malloc(sizeof(char) * len);
  18.     len = len - 1;
  19.     strncpy(supS,s,len);
  20.   }
  21.  
  22.   firstS = malloc(sizeof(char) * ((len/2)+1));
  23.   secondS = malloc(sizeof(char) * ((len/2)+1));
  24.   int i = 0;
  25.   int j = 0;
  26.   for(i;i<len;i++){
  27.     if(i < (len/2)){
  28.       firstS[i] = supS[i];
  29.       if(i == ((len/2)-1)){
  30.         firstS[i+1] = '\0';
  31.       }
  32.     }else{
  33.  
  34.       secondS[j] = supS[i];
  35.       if(i == (len-1)){
  36.           secondS[j+1] = '\0';
  37.       }
  38.       j++;
  39.     }
  40.   }
  41.   fun(firstS);
  42.   printf("%s\n",firstS );
  43.   //free(firstS);
  44.   //fun(secondS);
  45.   //printf("%s\n",secondS );
  46.   //free(secondS);
  47.   //printf("%s\n",supS );
  48.   //free(supS);
  49. }
  50.  
  51. int main(int argc,char ** argv){
  52.  
  53.   fun(argv[1]);
  54.  
  55.  
  56.   // printf("%d ",(int) getpid () );
  57.   // printf("%s \n",argv[1] );
  58.   // pid_t firstChild,secondChild;
  59.   // firstChild = fork();
  60.   //
  61.   // if(firstChild == 0){
  62.   //   printf("%d ",(int) getpid () );
  63.   //   printf("ab \n" );
  64.   // }
  65.   //
  66.   // secondChild = fork();
  67.   // if(secondChild == 0){
  68.   //   printf("%d ",(int) getpid () );
  69.   //   printf("cd \n");
  70.   // }
  71.   // pid_t child_pid;
  72.   // printf ("Program główny przed fork(), PID = %d\n", (int) getpid ());
  73.   // child_pid = fork ();
  74.   // if (child_pid > 0) {
  75.   // printf ("To jest proces macierzysty o numerze PID = %d\n", (int) getpid ());
  76.   // printf ("Numer PID potomka wynosi %d\n", (int) child_pid);
  77.   // }
  78.   // else if (child_pid == 0) {
  79.   // printf ("To jest proces potomny o numerze PID = %d\n", (int) getpid ());
  80.   // printf ("Numer PID procesu macierzystego wynosi %d\n", (int) getppid());
  81.   // }
  82.  
  83.  
  84.  
  85.  
  86.   return 0;
  87. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top