fork download
  1. #include<stdio.h>
  2. #include<unistd.h>
  3. #include<pthread.h>
  4. #include<string.h>
  5.  
  6. char length1[100];
  7. int length=0;
  8.  
  9. void *lengthstr(){
  10. length=strlen(length1);
  11. pthread_exit(NULL);
  12. }
  13.  
  14.  
  15. int main(){
  16. pthread_t thread;
  17. printf("* Enter the String: ");
  18. scanf("%[^\n]s", length1);
  19.  
  20. pthread_create(&thread, NULL, lengthstr, NULL);
  21. pthread_join(thread, NULL);
  22. printf("* Total length of string is: %d \n", length);
  23. return 0;
  24. }
Success #stdin #stdout 0.01s 5280KB
stdin
sunny saini
stdout
* Enter the String: * Total length of string is: 11