Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <string.h>
- void fun(char * s){
- int len;
- len = strlen(s);
- if(len == 0){
- return;
- }
- char * firstS;
- char *secondS;
- char *supS;
- if(len % 2 ){
- supS = malloc(sizeof(char) * len);
- len = len - 1;
- strncpy(supS,s,len);
- }
- firstS = malloc(sizeof(char) * ((len/2)+1));
- secondS = malloc(sizeof(char) * ((len/2)+1));
- int i = 0;
- int j = 0;
- for(i;i<len;i++){
- if(i < (len/2)){
- firstS[i] = supS[i];
- if(i == ((len/2)-1)){
- firstS[i+1] = '\0';
- }
- }else{
- secondS[j] = supS[i];
- if(i == (len-1)){
- secondS[j+1] = '\0';
- }
- j++;
- }
- }
- fun(firstS);
- printf("%s\n",firstS );
- //free(firstS);
- //fun(secondS);
- //printf("%s\n",secondS );
- //free(secondS);
- //printf("%s\n",supS );
- //free(supS);
- }
- int main(int argc,char ** argv){
- fun(argv[1]);
- // printf("%d ",(int) getpid () );
- // printf("%s \n",argv[1] );
- // pid_t firstChild,secondChild;
- // firstChild = fork();
- //
- // if(firstChild == 0){
- // printf("%d ",(int) getpid () );
- // printf("ab \n" );
- // }
- //
- // secondChild = fork();
- // if(secondChild == 0){
- // printf("%d ",(int) getpid () );
- // printf("cd \n");
- // }
- // pid_t child_pid;
- // printf ("Program główny przed fork(), PID = %d\n", (int) getpid ());
- // child_pid = fork ();
- // if (child_pid > 0) {
- // printf ("To jest proces macierzysty o numerze PID = %d\n", (int) getpid ());
- // printf ("Numer PID potomka wynosi %d\n", (int) child_pid);
- // }
- // else if (child_pid == 0) {
- // printf ("To jest proces potomny o numerze PID = %d\n", (int) getpid ());
- // printf ("Numer PID procesu macierzystego wynosi %d\n", (int) getppid());
- // }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement