Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Make a function substring() to extract a
- portion of a charcter string.
- subtring("charcter", 4, 3, result)
- extract 3 charters begining from charter 4, and put the
- result in array result*/
- #include <stdio.h>
- #include <string.h>
- void substring( char string[], int string_start, int string_lenght, char result[] )
- {
- int i = 0, j = 0;
- int count;
- char final_result[81];
- char null_zero[] = {"\0"};
- count = string_start + string_lenght;
- if( string[i] <= string_lenght)
- {
- string_start = 0;
- i = string_start;
- ++i;
- result[i] = string[i];
- }
- else
- {
- for(j = string_start ; j < count + 1; ++j, ++i)
- {
- result[i] = string[j];
- }
- }
- strcat(result, null_zero);
- // return result;
- }
- int main(void)
- {
- char word[] = {"character"};
- char result[81];
- int a = 4;
- int b = 20;
- substring( word , a , b, result);
- printf("%s\n", result);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement