Hi, how do I print a string such that only a section of it gets printed, without printing it character by character?
I thought of pointer arithmetic, but that will only change the starting point of the string for you. What I want to do is to print from start to (size of string - n).
I tried this:
char c, *pc; int size; scanf("%s", c); size = strlen(c); pc = c + size - 4; printf("%s\n", c - pc);
When I input "abcdefg", since pc points to "defg", I thought (c - pc) would give me "abc", but instead it gives a segfault. What should I do to just make it print "abc" without printing it char by char? Thanks!