storm@cs.mcgill.ca (Marc WANDSCHNEIDER) (03/14/91)
The following program WITHOUT The line #include <conio.h> does not work. It just freezes the entire system up, and I have to reboot (usin TC++ 1.0 on a PC). However, when I put the #include <conio.h>> line in, it doesn't even compile. I get LValue required in function main, and it point to the line c = 0; #include <stdio.h> #include <conio.h> main() { int i, test, c[25]; i = 0; c = 0; while ((i < 25) || (test !='A')) { test = getch(); c[i++] = test; } printf("\n\n %s", c); return 0; } Any insight...? Thanks! ./*- -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ storm@cs.mcgill.ca McGill University It's 11pm, do YOU Marc Wandschneider Montreal, CANADA know what time it is? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
n8840371@unicorn.cc.wwu.edu (Todd Crowe) (03/14/91)
Ok, I'll bite. I'm no C guru like some people are here, but I can answer this. storm@cs.mcgill.ca (Marc WANDSCHNEIDER) writes: >The following program WITHOUT The line #include <conio.h> does not work. It >just freezes the entire system up, and I have to reboot (usin TC++ 1.0 on a >PC). However, when I put the #include <conio.h>> line in, it doesn't even >compile. I get LValue required in function main, and it point to the line >c = 0; ^ | This should give you a good clue as to what is going on. >#include <stdio.h> >#include <conio.h> >main() >{ > int i, test, c[25]; > i = 0; > c = 0; > (rest of code deleted) >Any insight...? Yep. c is the name of an array. As such it is a constant value (i.e. it is not a valid lvalue). You are in effect trying to assign a value to a constant. I'm not quite sure what you are trying to do with but you need to either make it a scalar or an array but not both. +++++++++++++++ "Dont get your hair in an uproar!!!" +++++ +@+++++++++++++ +-----------------------------------------------------+ +++++ +++Western+++++ | Todd Crowe | +++++++Washington+++ | n8840371@unicorn.cc.wwu.edu | +++++++University+++ | TODDC@nessie.cc.wwu.edu | +++++++++++++++++++ +-----------------------------------------------------+ ++++++++++ "Innovate, don't litigate!"
tlglenn@cs.arizona.edu (Ted L. Glenn) (03/14/91)
In article <1991Mar13.223020.18117@cs.mcgill.ca>, storm@cs.mcgill.ca (Marc WANDSCHNEIDER) writes: | The following program WITHOUT The line #include <conio.h> does not work. It | just freezes the entire system up, and I have to reboot (usin TC++ 1.0 on a | PC). However, when I put the #include <conio.h>> line in, it doesn't even | compile. I get LValue required in function main, and it point to the line | c = 0; | #include <stdio.h> | #include <conio.h> | | main() | { | int i, test, c[25]; | | i = 0; | c = 0; [Rest of program deleted] Um, c by itself isn't an int. You have c declared as an array of ints. c[0] = c[1] =...= 0 would be legal. -- -Ted L. Glenn "Don't worry, be happy!" <--Ack! Pffffhhht! tlglenn@cs.arizona.edu G19382105@ccit.arizona.edu G19382105@ARIZRVAX.BITNET
Jon.Eric.Strayer@p3.f270.n231.z1.Fidonet.Org (Jon Eric Strayer) (03/18/91)
Marc WANDSCHNEIDER writes to All: The following program WITHOUT The line #include <conio.h> does not work. It just freezes the entire system up, and I have to reboot (usin TC++ 1.0 on a PC). However, when I put the #include <conio.h>> line in, it doesn't even compile. I get LValue required in function main, and it point to the line c = 0; #include <stdio.h> #include <conio.h> main() { int i, test, c[25]; i = 0; c = 0; while ((i < 25) || (test !='A')) { test = getch(); c[i++] = test; } printf("\n\n %s", c); return 0; } Any insight...? -------------------------------- I get the same result (Lvalue required) with or without includeing conio.h. I'm using TC++ 1.01, so that may be the reasong for differing results. But I don't see how you can be getting the above to compile in any case. If you want to assign zero to each element of an array you have to do just that. * Origin: Point No Point (Lebanon, IN) (1:231/270.3)
markh@csd4.csd.uwm.edu (Mark William Hopkins) (03/24/91)
In article <669422030.1@opocus.Fidonet.Org> Jon.Eric.Strayer@p3.f270.n231.z1.Fidonet.Org (Jon Eric Strayer) writes: >Marc WANDSCHNEIDER writes to All: > > #include <stdio.h> > #include <conio.h> ... > The following program WITHOUT The line #include <conio.h> does not > work. It just freezes the entire system up... ... <conio.h> routines can't be mixed with <stdio.h> routines.
sparks@power.viewlogic.com (Alan Sparks) (03/25/91)
In article <669422030.1@opocus.Fidonet.Org> you write: >Marc WANDSCHNEIDER writes to All: > > The following program WITHOUT The line #include <conio.h> does not > work. It just freezes the entire system up, and I have to reboot (usin TC++ > > #include <stdio.h> > #include <conio.h> > > main() > { > int i, test, c[25]; > > i = 0; > c = 0; ^^^^^^ THIS LINE SHOULD NOT COMPILE! > > while ((i < 25) || (test !='A')) { > test = getch(); > c[i++] = test; > } > printf("\n\n %s", c); > return 0; > } > > Any insight...? > >-------------------------------- >I get the same result (Lvalue required) with or without includeing conio.h. > > > * Origin: Point No Point (Lebanon, IN) (1:231/270.3) If your compiler let you do the above marked line, it's a bit brain- damaged... the standard (either one) does not sanction assignment to arrays. Initialization of c[] here should be do with a for loop. -Alan -- Alan Sparks voice: (508) 480-0881 Internet: sparks@viewlogic.com VIEWlogic Systems Inc., 293 Boston Post Rd. W., Marlboro MA 01752 Disclaimer: VIEWlogic didn't say this; I might have. Who's asking?
jlg@cochiti.lanl.gov (Jim Giles) (03/26/91)
In article <1991Mar25.145517.3427@viewlogic.com>, sparks@power.viewlogic.com (Alan Sparks) writes: |> |> In article <669422030.1@opocus.Fidonet.Org> you write: |> >Marc WANDSCHNEIDER writes to All: |> > [...] |> > int i, test, c[25]; |> > i = 0; |> > c = 0; |> ^^^^^^ |> THIS LINE SHOULD NOT COMPILE! |> [...] |> If your compiler let you do the above marked line, it's a bit brain- |> damaged... the standard (either one) does not sanction assignment to |> arrays. Initialization of c[] here should be do with a for loop. The program as written is wrong. But you shouldn't need a for loop. Why not do: int i = 0; int c[25] = {0}; int test; This should do what you want in both K&R and ANSI compliant code. J. Giles
gwyn@smoke.brl.mil (Doug Gwyn) (03/27/91)
In article <19058@lanl.gov> jlg@cochiti.lanl.gov (Jim Giles) writes: > int c[25] = {0}; >This should do what you want in both K&R and ANSI compliant code. No, that's an attempt to initialize an auto aggregate, which certainly is not required by the C language described in K&R 1st Edition. In practically all implementations, memset() would be a nice fast method of initializing an array of integer type to all zeros. To be absolutely safe, you need to use the obvious little loop.