Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. /* Make a function substring() to extract a
  2. portion of a charcter string.
  3. subtring("charcter", 4, 3, result)
  4. extract 3 charters begining from charter 4, and put the
  5. result in array result*/
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. void substring( char string[], int string_start, int string_lenght, char result[] )
  11. {
  12. int i = 0, j = 0;
  13. int count;
  14. char final_result[81];
  15. char null_zero[] = {"\0"};
  16.  
  17.  
  18.  
  19.  
  20. count = string_start + string_lenght;
  21.  
  22. if( string[i] <= string_lenght)
  23. {
  24. string_start = 0;
  25. i = string_start;
  26. ++i;
  27.  
  28. result[i] = string[i];
  29. }
  30.  
  31. else
  32. {
  33. for(j = string_start ; j < count + 1; ++j, ++i)
  34. {
  35.  
  36. result[i] = string[j];
  37.  
  38. }
  39. }
  40.  
  41. strcat(result, null_zero);
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. // return result;
  53. }
  54.  
  55. int main(void)
  56. {
  57. char word[] = {"character"};
  58. char result[81];
  59. int a = 4;
  60. int b = 20;
  61.  
  62. substring( word , a , b, result);
  63. printf("%s\n", result);
  64.  
  65.  
  66.  
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement