Advertisement
Guest User

Untitled

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