   file io
  I want to read every character on one line into a variable.  I don''t think fscanf can do this because there is no way to tell whether you have gone onto the next line or not, right?  So, I''m trying to use fgets but this is also reading tabs and other marks that I dont'' want to take out because it makes everything hard to read.  Any suggestions? 
  If you want to use fscanf: FILE* fp = fopen( "foo.txt", "r" );int nchar;char buf[1024];fscanf( fp, "%1023[^\n]%n", buf, &nchar);if( nchar == 1023 ){   puts( "Line too long." );}A line longer than 1023 characters will be truncated, and the next fscanf call will pick up where the previous one stopped.    “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”    — Brian W. Kernighan (C programming language co-inventor) [edited by - Fruny on February 11, 2004 12:36:02 PM];  It's ok if it misses some text at the end, is there any way to read it like you did then move it to the next line so it start there instead of reading the rest?edit: actually wouldn't that stop when it met a space, It needs to keep reading past spaces   [edited by - crazedfool on February 11, 2004 12:38:54 PM];  Or, in C++ #include <fstream>#include <string>std::ifstream ifs("foo.tx");std::string buf;std::getline( ifs, buf ); “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”    — Brian W. Kernighan (C programming language co-inventor);quote:Original post by crazedfool  It''s ok if it misses some text at the end, is there any way to read it like you did then move it to the next line so it start there instead of reading the rest?   fscanf( fp, "%*[^\n]" );Will read all characters which are not a newline, but this time discards them.   “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”    — Brian W. Kernighan (C programming language co-inventor);  I use FILE, and I think fscanf stops when it hits a space which isn't what I want it to do.edit: you beat me, thanks   [edited by - crazedfool on February 11, 2004 12:41:43 PM];quote:actually wouldn''t that stop when it met a space, It needs to keep reading past spaces.If you were to use "%1023s" then yes, it would stop at spaces. But "%1023[^\n]" stops only at newlines. Read the scanf documentation carefully.   “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”    — Brian W. Kernighan (C programming language co-inventor);  Grr..Now it''s reading in all the spacing again, is there anyway to ignore the spacing around the text and just read the characters just until it gets to the end of the line.  I''ve tried loading single chars but I can''t get it right, how do you put them together to a char*. ;  Give me a sample line and how you want it to be interpreted and I''ll see what I can do. You''re not being clear on what you want...   “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”    — Brian W. Kernighan (C programming language co-inventor);  It's loading information from a text file about how to make a menu.  Most of the lines are all set up just using fscanf but one line is the commands to execute when the button is clicked.  I want it to read it without spacing that I put there to make it legible and easier to understandBUTTON ACTIONLOAD_MENU("Images\Menu\Single\single_menu.txt");   GAME_MODE_SWITCH(MODE_SMENU);...other stuffIt goes on and all put together is annoying to read so I want it to ignore spaces and read in just the characters.  Really I want to ignore line ends too and just stop when I reach I new atrribute.What I really need is some way to get the strings without the spaces inbetween them and then combine them together to make the final.edit:really there is more space, except the html interprets it, sorry for being unclear at the start.   [edited by - crazedfool on February 11, 2004 1:00:07 PM]