Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #define ROW 8
  6. #define COLUMN 8
  7.  
  8. int main()
  9. {
  10. char* test = "You are retarded!";
  11. char *newchar;
  12. int i;
  13. int k = 0;
  14. int nc;
  15.  
  16. int copy_flag = 0;
  17.  
  18. newchar = (char *)malloc(strlen(test));
  19.  
  20. if (!newchar)
  21. {
  22. printf("Could not allocate memory!");
  23. exit(1);
  24. }
  25.  
  26. for(nc = 0; nc < strlen(test); ++nc)
  27. {
  28. int loop = 0;
  29. if(test[nc] == ' ' && copy_flag == 1 && loop != 1)
  30. {
  31. //printf("flag is off\n");
  32. copy_flag = 0;
  33. loop = 1;
  34. }
  35. if(copy_flag == 1)
  36. {
  37. //printf("%c\n", test[nc]);
  38. newchar[k] = test[nc];
  39. k++;
  40. newchar[k] = '\0';
  41. }
  42. if(test[nc] == ' ' && copy_flag == 0 && loop != 1){
  43. //printf("flag is on\n");
  44. copy_flag = 1;
  45. loop = 1;
  46. }
  47. }
  48. printf(newchar);
  49. free(newchar);
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement