Struggling with using TAB along with insert to move characters in a string.
Code:
case TAB_KEY:
for(j=0;j<TAB_SIZE;j++){
if(!*ins){
if(ch =32){
for (i = strlen(str); i >= ctr; i--){
str[i + 1] = str[i];
}
str[ctr] = ch;
if (*curpos < flen - 1)
{
(*curpos)++;
ctr++;
}
}
}
I am designing a single line text editor using C.
For you guys to understand
TAB_SIZE is defined in a define statement which is between either 2 or 8. *ins is a pointer flag for insert mode or not. ch is the ASCII character for space which is integer 32. *curpos is a pointer to the current cursor position. str is the string and flen is the field length. CTR is an integer (counter) just set to 0 initially.
What this code will do will shift all characters to the right, if the cursor is set to 0 on the first character and put the number of TAB_SIZE spaces before the characters. This is good, if my TAB_SIZE is 4 and I hit TAB with insert on, characters will be shifted, 4 spaces inserted before the string.
When I have my cursor in the middle of the string and hit TAB, this is where I am confused, I am not sure how I can split the string at the cursor position and shift the characters right with the number of TAB_SIZE spaces.
I would appreciate any tips for anyone who is good at character manipulation in a Win32 console.
Thanks in advance.