fork(1) download
  1. #include <stdio.h>
  2.  
  3. int my_strrchr(const char *ptr, const char delimiter);
  4.  
  5. int main(void){
  6. char arr[] = "4.1.2017.";
  7. char delimiter = '.';
  8.  
  9. int len;
  10.  
  11. if( (len = my_strrchr(arr, delimiter)) > 0){
  12. while ( arr[len] != '\0'){
  13. arr[len] = '\0';
  14. }
  15. printf("%s\n", arr);
  16. }
  17. }
  18.  
  19. int my_strrchr(const char *ptr, const char delimiter){
  20. if (ptr == NULL ){
  21. printf("Error, NULL Pointer\n");
  22. return -1;
  23. }
  24.  
  25. if ( *ptr == '\0' ){
  26. printf("Error, the Buffer is Empty\n");
  27. return 0;
  28. }
  29.  
  30. int i = 0;
  31. int ret = 0;
  32.  
  33. while( ptr[i] != '\0' ){
  34. if ( ptr[i] == delimiter ){
  35. ret = i;
  36. }
  37. i++;
  38. }
  39.  
  40. return ret;
  41. }
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
4.1.2017