Hello, I'm a scheme programmer teaching myself C with the K and R book (what can I say, I'm bored with my Java OOP class). The end of chapter one asks you to write a function to replace all tabs with a set number of spaces. So I wrote the function below. Anyhow, the program works fine if I enter no tabs, but if I enter a tab it goes into a never ending loop.
Two questions:
1) Why
2) A *tip* on what a better way to solve this is
I know there are answers that can be found online, but they are not very helpful to a C-novice like myself because they do not explain precisely what they or are doing, or more importantly, why.
Code:void detab(char s[], char x[], int space) { int i; i = 0; while(s[i] != '\0') { if (s[i] == '\t') { for(int y = space; y == 0; y--) x[i+y] = ' '; } else { x[i] = s[i]; i++; } } } /** note: to compile this use: gcc -std=gnu99