If there is a file with words on each line; what method can I use to identify the last letter on each line.
Please help. I have just this one issue to resolve in my program.
If there is a file with words on each line; what method can I use to identify the last letter on each line.
Please help. I have just this one issue to resolve in my program.
Get each line one at a time and then use something like strlen() to find the end and go from there.
Windows XP Home Edition - Dev-C++ 4.9.9.2
board.theprogrammingsite.comOriginally Posted by "The C Programming Language" by Brian W. Kernignhan and Dennis M. Ritchie
The last letter on each line is always going to precede the the '\n' character. Unless the '\n' is the first character on the line in which case there is no last letter on the line
If you understand what you're doing, you're not learning anything.
Not always. A file doesn't have to have a blank line at the end (although it makes life easier if it does!).The last letter on each line is always going to precede the the '\n' character
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Thanks.
So, are you the fact that the last letter on each line of an input line of words will be a '\0'?
I was under the impression the last character in a string array only could be be a null character.
No, see, when you read in a string with fgets(), it reads until the size of the buffer or EOF or a newline is reached. So oftentimes the buffer ends with '\n\0'.
All strings in C end with a NULL character.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
If you read multiple lines of a file at once eg. with fread(), there could be multiple newlines. Of course, with fread() no terminator is appended.
Code:#include <stdio.h> void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){ puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9 /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i] ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][ t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}
Sorry, I misread your question. NULL and '\0' and 0 are the same thing: FAQ > What's the difference between... > NULL, 0, \0 and nul?Thanks.
So, are you the fact that the last letter on each line of an input line of words will be a '\0'?
I was under the impression the last character in a string array only could be be a null character.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.