Gets.cpp 747 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #include <stdio.h>
  11. #include <string.h>
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. char * Gets ( char * str, int num )
  16. {
  17. fgets(str, num, stdin);
  18. if (str[0]=='\n' || str[0]=='\r')
  19. str[0]=0;
  20. size_t len=strlen(str);
  21. if (len>0 && (str[len-1]=='\n' || str[len-1]=='\r'))
  22. str[len-1]=0;
  23. if (len>1 && (str[len-2]=='\n' || str[len-2]=='\r'))
  24. str[len-2]=0;
  25. return str;
  26. }
  27. #ifdef __cplusplus
  28. }
  29. #endif
粤ICP备19079148号