fork download
  1. #include <stdio.h>
  2.  
  3. void removeDuplicateSpaces(char a[]){ //a-b---c
  4. // char *a=*c;
  5. char *b=malloc(sizeof(char)*strlen(a));
  6. if(b==0){
  7. return;
  8. }
  9. int i=0,nf=0,space=0;
  10. for(;a[i]!='\0';i++){
  11. if(a[i] != ' '){ //a-b-
  12. if(space>1){
  13. b[nf]=a[i];
  14. nf++;
  15. space=0;
  16. }else{
  17. b[nf]=a[i];
  18. nf++;
  19. }
  20. }else{
  21. space++;
  22. if(space==1 && i!=0){
  23. b[nf]=' ';
  24. nf++;
  25. }
  26. }
  27. }
  28. b[i]='\0';
  29. strcpy(a,b);
  30. }
  31.  
  32. int main(void) {
  33. char *a=" Arista is hiring from ISM Dhanbad";
  34. removeDuplicateSpaces(a);
  35. printf("%s",a);
  36. free(a);
  37. return 0;
  38. }
  39.  
Runtime error #stdin #stdout 0s 2376KB
stdin
Standard input is empty
stdout
Standard output is empty