I don't really understand what you're trying to do. "Spaces and diacritic"?
I'm guessing that at the moment your code is trying to write the input into a file with all whitespaces (e.g. tabs, newlines) replaced by single space characters? If that's not what it's meant to do, then it'd be helpful if you could explain. If you could show an input line and what you'd expect to see from the output that'd help a lot.
Code:
for(i=0;i<=MAX;i++) {
c[i] = getchar();
if(!(isalpha(c[i]))) {
c[i] = '\0';
}
This will write '\0' into any non alphabetic character, including digits, spaces, and probably diacritics.
Code:
if(c[i] == '\0') {
break;
Then straight away the code will break out of the loop. So it'll only read the characters from the input up to the first non alphabetic character.
I don't think that's what you intended, since you have code to deal with spaces later. I think you need to pick an "end of string" character in case the input string is less than MAX chars. EOF is the usual one: Ctrl+Z on Windows, CTRL+D on Linux. to check it, do:
Code:
for(j=0;j<=c[MAX-1];j++) {
Your loop termination condition isn't right here. c[MAX-1] is the last value read into the array. I'd personally say you should be comparing against i here:
Code:
for(j=0;j<=i;j++) {
To output only as much as you input.
Code:
for(j=0;j<=c[MAX-1];j++) {
if(isspace(c[j])) {
c[j] = ' ';
break;
}
fputs(c, soubor);
}
So, here I think you're trying to go through the whole of c and replace all whitespace characters (tab, newline, space) with a single space character. Then output the resulting string?
What you code actually does is (assuming the for loop is corrected):
Code:
for(j=0;j<=MAX;j++) { // for loop starts here
if(isspace(c[j])) { // "if" statement starts
c[j] = ' ';
break; // break out of the for loop
} // "if" statement ends
fputs(c, soubor);
} // for loop ends
c always points at the beginning of the string - so each time round the for loop the same string will be printed. I'm not sure why you have a break statement here -- why would you want to stop when you reach a space?
Sorry if this has been really unhelpful, but I just don't know what you're trying to do!