fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main()
  4. {
  5.  
  6. char text[100], result[100];
  7. int i, j = 0;
  8. printf("Enter text with spaces: ");
  9. fgets(text, sizeof(text), stdin);
  10. // loop through each character of the text
  11. for (i = 0; i < strlen(text); i++)
  12. {
  13.  
  14. // if the current character is not a space, add it to the result
  15. if (text[i] != ' ')
  16. {
  17.  
  18. result[j] = text[i];
  19. j++;
  20. }
  21.  
  22. }
  23.  
  24. // add null terminator at the end of the result
  25.  
  26. result[j] = '\0';
  27.  
  28. printf("Text without spaces: %s\n", result);
  29. return 0;
  30. }
Success #stdin #stdout 0.01s 5476KB
stdin
DHANIMIREDDY SHAKYA
stdout
Enter text with spaces: Text without spaces: DHANIMIREDDYSHAKYA