char stream[sizeof(int)];
char Mat_file[sizeof(int)];
...
if(S_stream == "*BITMAP")
{
fscanf(infile, "%s", &stream);
Mat_array[num_mat].Mat_file = stream;
}
any ideas?
Umm... yeah... that would be great... -Bill Lumberg
l-values???
i keep getting this error of there is no l-value (C2106). i have looked it up on the MSDN but no luck understanding it. what does that mean? here is a bit of code if it helps:
quote:
MSDN
Expressions in C++ can evaluate to “l-values” or “r-values.” L-values are expressions that evaluate to a type other than void and that designate a variable.
L-values appear on the left side of an assignment statement (hence the “l” in l-value). Variables that would normally be l-values can be made nonmodifiable by using the const keyword; these cannot appear on the left of an assignment statement. Reference types are always l-values.
Here:
int a;const int b;a = 10; // This works. A is an 'l-value' == it may appear on the left side.10 = a; // NOPE. 10 is not an l-value.b = 10;// NOPE. b is const and can't be on the left side (l-value)
quote:
if(S_stream == "*BITMAP")
^
Can strings be compared using ==?
No, they can't. You'll have to use strcmp(...), or switch to std::string in the first place.
char stream[sizeof(int)];
This is probably the line you're getting the error at. Arrays must be created using const values(C++ only), or immediate values (C,C++), like so:
char stream[10];
[edited by - Wildfire on August 20, 2003 3:28:18 AM]
How do I set my laser printer on stun?
Wildfire, sizeof(int) is a constant value
adam17,
Mat_array[num_mat].Mat_file = stream;
but Mat_array was declared as a character array, which means you can do indexing on it, but a char has no data members so you can't do .something after it
[edited by - tricona on August 20, 2003 8:18:37 AM]
adam17,
Mat_array[num_mat].Mat_file = stream;
but Mat_array was declared as a character array, which means you can do indexing on it, but a char has no data members so you can't do .something after it
[edited by - tricona on August 20, 2003 8:18:37 AM]
quote:
Wildfire, sizeof(int) is a constant value
Ehr... oops, yeah... Still it doesn''t make much sense in this example. On a Win/Linux your string will be 4 characters long, with Dos 2 characters. Why? How does the string size depend on the size of an int in your case?.
If the string read by fscanf(infile, "%s", &stream) is larger then that, you might get memory access violation.
quote:
...Mat_array was declared as a character array...
Mat_array was not declared at all. He only declares Mat_file as a char[], but I don''t see a definition of Mat_array anywhere...
All in all, a pretty weird piece of code.
How do I set my laser printer on stun?
quote:
Original post by Wildfire
Mat_array was not declared at all. He only declares Mat_file as a char[], but I don''t see a definition of Mat_array anywhere...
All in all, a pretty weird piece of code.
oops, guess i should look a little closer. but either way, in order to use the . operator, it still needs to be a data type with either data members or member functions (if it has member functions, then normally it would also have data members, though in theory doesn''t have to, have yet to find a situation for this yet, but also haven''t looked), and that means struct or class. the usage of the . operator is still my best guess given the limit code sample for where the error is occuring. also, most compilers give line numbers (which are normally useful) for the line the error is on.
No disagreement about the strangeness of the piece of code.
You can''t assign to an array, only to array elements.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"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
Tricona: Yep, you''re right about the ''.''. My best guess would be that Mat_array is supposed to be an array of structs[] and Mat_file maybe a member of that struct.
But unless Adam17 is going to provide a more complete sample of his code (with the line the error is in this time), we''ll be pretty much guessing blindly.
Fruny: Right, = doesn''t work for char-strings...
I think some C-teachers would be happy about this code for the infamous ''how many errors can you see'' test...
But unless Adam17 is going to provide a more complete sample of his code (with the line the error is in this time), we''ll be pretty much guessing blindly.
Fruny: Right, = doesn''t work for char-strings...

I think some C-teachers would be happy about this code for the infamous ''how many errors can you see'' test...
How do I set my laser printer on stun?
quote:
Original post by Wildfire
I think some C-teachers would be happy about this code for the infamous ''how many errors can you see'' test...
http://www.ioccc.org/
not the most erros, but the most unreadable code contest
quote:
http://www.ioccc.org/
not the most erros, but the most unreadable code contest
Thanks, I know those guys

What I was refering to, was what some of our so called ''programming teachers'' in university did.
They''d print out a page full of code, tell you "there''s 42 errors in there, go", and you had to try and find all of ''em... things like missing semicolons etc. What am I, a living compiler??? One of the teachers even tried to force us to write code in vi, so we couldn''t use the compiler to find errors. He thought it would teach us to write better code...

I think there''s quite a difference between doing no syntax errors and writing good code... but blah...
Here''s something I wrote for an university assignement... just for the fun of it


Input::Input(char** stream,byte length){ t.length^=t.length; //t.length is a member of the class while((t.input=getch())!=0x0D||t.length<1) t.input!=0x30&&t.input!=0x31||t.length>length-1?t.input!=27?t.input==''\b''&&t.length?printf("\b \b",t.length--):putchar(''\a''):throw Quit():((*stream)=(char*)realloc(*stream,(t.length+2)*sizeof(char)))[t.length++]=(char)putchar(t.input); (*stream)[t.length]^=(*stream)[t.length];}
How do I set my laser printer on stun?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement