1. /*********************************************************************************/
  2. /* Assignment 1: String Delete Then Add ******************************************/
  3. /* Name: Jaemyeong Eo *****************************************************/
  4. /*********************************************************************************/
  5.  
  6. /*********************************************************************************/
  7. /* Usual suspects to include *****************************************************/
  8. /*********************************************************************************/
  9. #include<stdio.h>
  10. #include<stdlib.h>
  11. #include<string.h>
  12. #include<unistd.h>
  13.  
  14. /*********************************************************************************/
  15. /* Global string which to operate on *********************************************/
  16. /*********************************************************************************/
  17. char string[1024];
  18.  
  19. /*********************************************************************************/
  20. /* delete_then_add function ******************************************************/
  21. /*********************************************************************************/
  22. void delete_then_add( char *string, int len )
  23. {
  24. int i=0;
  25. int count_as=0;
  26. int count_bs=0;
  27.  
  28. count_as = count_bs = i; // get rid of warning
  29.  
  30.  
  31.  
  32. // YOUR WRITE THIS FUNCTION -- it's short on code, but a little tricky to get right
  33. // first phase - remove the B's but don't pass over newling "\n"
  34. // second phase - add the a's starting at the back and move to the front of the string
  35.  
  36. }
  37.  
  38. /*********************************************************************************/
  39. /* main function *****************************************************************/
  40. /*********************************************************************************/
  41.  
  42. int main( )
  43. {
  44. printf("Please enter a string with a's and b's in it: \n");
  45. if( NULL == fgets(string, 1024, stdin))
  46. {
  47. printf("Error in reading string from stdin");
  48. exit(-1);
  49. }
  50.  
  51.  
  52. delete_then_add( string, strlen(string) );
  53. printf("The new string is: %s\n", string );
  54.  
  55. return(0);
  56. }
  57.