Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3.  
  4. char* string();
  5.  
  6. int main() {
  7.  
  8. printf("%s", string());
  9.  
  10. return 0;
  11. }
  12.  
  13. char* string() {
  14. char input[128];
  15. printf("enter a word: ");
  16. scanf("%s", input);
  17. int counter = 0;
  18. char temp[128];
  19. int i = 0;
  20. while (i < input[i]) {
  21. if ('a' <= input[i] && input[i] <= 'z') {
  22. temp[counter] = input[i];
  23. counter++;
  24. }
  25. else if ('A' <= input[i] && input[i] <= 'Z') {
  26. temp[counter] = input[i]+32;
  27. counter++;
  28. }
  29. else if (input[i] == '.' || input[i] == ',' || input[i] == '?' || input[i] == '!') {
  30. temp[counter] = input[i];
  31. counter++;
  32. }
  33. i++;
  34. }
  35. char* output = (char*)malloc(counter * sizeof(char));
  36. i = 0;
  37. while (i < counter) {
  38. *(output + i) = temp[i];
  39. i++;
  40. }
  41. *(output + counter) = '\0';
  42.  
  43.  
  44. return output;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement