c - need to write a function that takes a string an integer offset and size and prints starting from offset and upto offset+size the string -
the idea trim string starting value of offset , upto value of size , return along new string return 1; , if gets outside of code boundery return 0 . code:
int subprint(char *s, int offset,int size){ char *m; m = (s + offset); while(size != 0){ m = (m + 1); if(m == '\0') return 0; size--; } s = m; return 1; } void subprinttest(){ char s[20] = "industrial"; subprint(s,2,4); printf("%s",s); } void main(){ subprinttest(); getch(); }
the problem printing original string s unchanged
the issue having pointer s being passed value function subprint. in order intend, pass pointer pointer s.
Comments
Post a Comment