dev-cpp-users Mailing List for Dev-C++ (Page 575)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
You can subscribe to this list here.
| 2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(15) |
Oct
(115) |
Nov
(154) |
Dec
(258) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2001 |
Jan
(377) |
Feb
(260) |
Mar
(249) |
Apr
(188) |
May
(152) |
Jun
(150) |
Jul
(195) |
Aug
(202) |
Sep
(200) |
Oct
(286) |
Nov
(242) |
Dec
(165) |
| 2002 |
Jan
(245) |
Feb
(241) |
Mar
(239) |
Apr
(346) |
May
(406) |
Jun
(369) |
Jul
(418) |
Aug
(357) |
Sep
(362) |
Oct
(597) |
Nov
(455) |
Dec
(344) |
| 2003 |
Jan
(446) |
Feb
(397) |
Mar
(515) |
Apr
(524) |
May
(377) |
Jun
(387) |
Jul
(532) |
Aug
(364) |
Sep
(294) |
Oct
(352) |
Nov
(295) |
Dec
(327) |
| 2004 |
Jan
(416) |
Feb
(318) |
Mar
(324) |
Apr
(249) |
May
(259) |
Jun
(218) |
Jul
(212) |
Aug
(259) |
Sep
(158) |
Oct
(162) |
Nov
(214) |
Dec
(169) |
| 2005 |
Jan
(111) |
Feb
(165) |
Mar
(199) |
Apr
(147) |
May
(131) |
Jun
(163) |
Jul
(235) |
Aug
(136) |
Sep
(84) |
Oct
(88) |
Nov
(113) |
Dec
(100) |
| 2006 |
Jan
(85) |
Feb
(119) |
Mar
(33) |
Apr
(31) |
May
(56) |
Jun
(68) |
Jul
(18) |
Aug
(62) |
Sep
(33) |
Oct
(55) |
Nov
(19) |
Dec
(40) |
| 2007 |
Jan
(22) |
Feb
(49) |
Mar
(34) |
Apr
(51) |
May
(66) |
Jun
(43) |
Jul
(116) |
Aug
(57) |
Sep
(70) |
Oct
(69) |
Nov
(97) |
Dec
(86) |
| 2008 |
Jan
(32) |
Feb
(47) |
Mar
(106) |
Apr
(67) |
May
(28) |
Jun
(39) |
Jul
(31) |
Aug
(25) |
Sep
(18) |
Oct
(25) |
Nov
(5) |
Dec
(21) |
| 2009 |
Jan
(33) |
Feb
(27) |
Mar
(27) |
Apr
(22) |
May
(22) |
Jun
(10) |
Jul
(17) |
Aug
(9) |
Sep
(21) |
Oct
(13) |
Nov
(4) |
Dec
(11) |
| 2010 |
Jan
(10) |
Feb
(8) |
Mar
(4) |
Apr
(1) |
May
|
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(8) |
Oct
(26) |
Nov
(9) |
Dec
(1) |
| 2011 |
Jan
(21) |
Feb
(16) |
Mar
(4) |
Apr
(19) |
May
(26) |
Jun
(9) |
Jul
(6) |
Aug
|
Sep
(4) |
Oct
(3) |
Nov
(2) |
Dec
(1) |
| 2012 |
Jan
(4) |
Feb
(7) |
Mar
(4) |
Apr
|
May
(1) |
Jun
(10) |
Jul
(1) |
Aug
(1) |
Sep
(18) |
Oct
(3) |
Nov
(1) |
Dec
(1) |
| 2013 |
Jan
(4) |
Feb
(2) |
Mar
(15) |
Apr
(6) |
May
(1) |
Jun
(3) |
Jul
(1) |
Aug
(2) |
Sep
(4) |
Oct
|
Nov
(9) |
Dec
|
| 2014 |
Jan
(4) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(5) |
Aug
(4) |
Sep
|
Oct
(2) |
Nov
(1) |
Dec
(4) |
| 2015 |
Jan
(2) |
Feb
(3) |
Mar
(1) |
Apr
(2) |
May
(1) |
Jun
(2) |
Jul
|
Aug
(1) |
Sep
(2) |
Oct
(9) |
Nov
(35) |
Dec
(6) |
| 2016 |
Jan
(7) |
Feb
(10) |
Mar
(10) |
Apr
(9) |
May
(13) |
Jun
(9) |
Jul
(1) |
Aug
(3) |
Sep
(3) |
Oct
(1) |
Nov
(1) |
Dec
|
| 2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2019 |
Jan
(1) |
Feb
|
Mar
|
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2020 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Ioannis V. <no...@ho...> - 2002-06-09 18:07:20
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Raghunath Marella.S > Sent: Sunday, June 09, 2002 12:42 PM > To: dev...@li... > Subject: [Dev-C++] memory violation.... > > > Hi, > > I have been facing a simple but strange problem in my > C++ code. I have declared an integer pointer and whose > size has been fixed at a large value dynamically. > Like... > > seneles = 1000,ncn = 6; You forgot the type, e.g. int. > int *EleTopo = new int[seneles*ncn]; > > Once this block is filled with valid data, once those > values are printed and observed they seem to be > correct. But in between of the code, retrieving the > same had returned some junk values for some of the > indexes. Obviously you are doing something wrong. We must see the code. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys |
|
From: Napoleon A. <nah...@so...> - 2002-06-09 15:30:49
|
Hello Folks, I will like to know if wxWindows 2.2.9 ODBC clases work with the = Firebird database engine. I'm looking at Firebird because I have = problems connecting to my mySQL data sources. Also does any one know where I can download a C language reference = manual ? I have mistakenly deleted my but I can't seem to find any = downlodable copies on the net. Thnxs Napoleon. --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.370 / Virus Database: 205 - Release Date: 05/06/02 |
|
From: Daniel G. <sp...@ho...> - 2002-06-09 12:06:32
|
Try declaring the pointer as a char, instead of an int. Remember that the type of pointer is what it can point to. So an int cannot point to a char variable for example. Does that sound right to everyone? Daniel >From: "Raghunath Marella.S" <ms...@ya...> >To: dev...@li... >Subject: [Dev-C++] memory violation.... >Date: Sun, 9 Jun 2002 02:42:00 -0700 (PDT) > >Hi, > >I have been facing a simple but strange problem in my >C++ code. I have declared an integer pointer and whose >size has been fixed at a large value dynamically. >Like... > >seneles = 1000,ncn = 6; >int *EleTopo = new int[seneles*ncn]; > >Once this block is filled with valid data, once those >values are printed and observed they seem to be >correct. But in between of the code, retrieving the >same had returned some junk values for some of the >indexes. > >I am not getting what could be the problem. >Will any one please help me out in this. > >thanks in advance, > >regards, >Raghunath > >__________________________________________________ >Do You Yahoo!? >Yahoo! - Official partner of 2002 FIFA World Cup >http://fifaworldcup.yahoo.com > >_______________________________________________________________ > >Don't miss the 2002 Sprint PCS Application Developer's Conference >August 25-28 in Las Vegas - >http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink > >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ Join the worlds largest e-mail service with MSN Hotmail. http://www.hotmail.com |
|
From: Raghunath Marella.S <ms...@ya...> - 2002-06-09 09:42:00
|
Hi, I have been facing a simple but strange problem in my C++ code. I have declared an integer pointer and whose size has been fixed at a large value dynamically. Like... seneles = 1000,ncn = 6; int *EleTopo = new int[seneles*ncn]; Once this block is filled with valid data, once those values are printed and observed they seem to be correct. But in between of the code, retrieving the same had returned some junk values for some of the indexes. I am not getting what could be the problem. Will any one please help me out in this. thanks in advance, regards, Raghunath __________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com |
|
From: Ioannis V. <no...@ho...> - 2002-06-09 03:17:31
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of rchavez > Sent: Sunday, June 09, 2002 5:23 AM > To: dev...@li... > Subject: [Dev-C++] short integer problem > > > Thanks for all the useful replies on this. They helped me > clear up some > other minor mysteries regarding double variables. My text > did not mention > format specifiers hd, le or lg at the appropriate times ( only in the > appendix once I knew what I was looking for ). > > Two related questions if I may: > > double should be equivalent to long float but long float > gives compiler > error. Was the ANSI standard changed? The latest ANSI C standard was ratified in 1999. However a long float type never existed. The built in non-pointer types of ANSI C 1989 (not mentioning signed and unsigned integer types explicitly) are: char, short, int, long, float, double and long double. > long double compiles but I get strange behavior as I did > for short when > using %d instead of %hd. I looked for long double in > Kernighan & Ritchie > but saw only the modifiers h & l. Is there a format > specifier for long > double? Yes. %lf. However long double has extremelly high precision and that means some time cost. Use long double when you want very very high floating point precision. In almost all cases float and double (when you want high precision) are sufficient. > If not, why do I not get an error in compiling as I > did for short > char? C has not a strong type safe system. Also it is very hard to check argument validity in variadic functions. Also there is not a short char type and i do not understand completely what warnings you mean. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys |
|
From: rchavez <rc...@so...> - 2002-06-09 02:22:55
|
Thanks for all the useful replies on this. They helped me clear up some other minor mysteries regarding double variables. My text did not mention format specifiers hd, le or lg at the appropriate times ( only in the appendix once I knew what I was looking for ). Two related questions if I may: double should be equivalent to long float but long float gives compiler error. Was the ANSI standard changed? long double compiles but I get strange behavior as I did for short when using %d instead of %hd. I looked for long double in Kernighan & Ritchie but saw only the modifiers h & l. Is there a format specifier for long double? If not, why do I not get an error in compiling as I did for short char? Rob |
|
From: Jason H. <jas...@nt...> - 2002-06-08 22:31:02
|
Quick tip:
get 'a'
get 'b'
repeat
if 'a' is greater than 'b'
output 'b'
get 'b'
else
output 'a'
get 'a'
until one of the streams is empty
This is a simplistic algorithm for you to follow, but it demonstrates the way two sorted streams can
be "merged" (lookup that word in an algorithms book). There is still one more thing for you to add:
When one of the streams runs out then you need to continue feeding from the other and outputing it
until it is also empty. And don't forget that the streams may be empty to start with! (tip: use a
while loop)
It would be wise for you to figure the rest out yourself, but one more tip: If you are repeating the
same steps several times in different places in a program, then it's a good idea to make those steps
into a function (i.e. getFromStream(); outputToStream();). Meaningful variable names also help
(instream_a, instream_b, outstream)
Jason.
PS: Not as quick a tip as I had planned, but at least I didn't hand everything to you on a plate.
PPS: This is a repost, my first one didn't seem to get through.
----- Original Message -----
From: "chromatonus 712" <chr...@ho...>
To: <dev...@li...>
Sent: Saturday, June 08, 2002 1:48 AM
Subject: [Dev-C++] merging two sorted lists using file streams...
Hi, here is my program that is suppose to read one piece of data from 2
different sorted lists each,
like these two text files:
File A:
1
2
4
8
16
File B:
0
1
1
2
3
5
8
output should be
File C:
0 1 1 1 2 2 3 4 5 8 8 16
Would anyone give a sample program that performs this function, using only
the "basic" file stream operations as in my program below? Thank you very
much
#include "apstring.h"
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
int main()
{
ifstream a; ifstream b;
ofstream c;
a.open("A.dat");
b.open("B.dat");
int ark, bum, j, k, temp;
a >> ark;
a.ignore(80,'\n');
j = ark;
b >> bum;
b.ignore(80,'\n');
k = bum;
if( ark < bum )
{
c << ark << endl;
a >> ark;
a.ignore(80,'\n');
temp = ark;
}
else
{
c << bum << endl;
b >> bum;
b.ignore(80,'\n');
temp = bum;
}
if(j<k)
{
while( b>>bum && bum<temp )
{
b >> bum;
b.ignore(80,'\n');
c << bum << endl;
b >> bum;
b.ignore(80,'\n');
}
c << temp << endl;
temp = bum;
}
else
{
while( a>>ark && ark<temp )
{
a >> ark;
a.ignore(80,'\n');
c << ark << endl;
a >> ark;
a.ignore(80,'\n');
}
c << temp << endl;
temp = ark;
}
while( c << temp )
{
cout << temp << endl;
}
system("PAUSE");
a.close();
b.close();
c.close();
return 0;
}
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
_______________________________________________________________
Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas - http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Carlos d. M. <cg...@wo...> - 2002-06-08 19:26:55
|
Hi:
I have problem I want solve by bit shifts. Below I add the code (one of
the many versions I tried) so you can see it and know better what I am
searching. The thing I cannot do at any way is the shifting phase
(obviously, if not the subject would have been another).
I want take some bytes and put them in a variable with more than one
byte of width. For example, a double or a long double variable.
So I try unsigned char unschar; I make an struct with eight unschar, I
assign the first eight bits to the first and shift it 7*8 places when
assigning to double, the next 8 bits to the second, shifting eight bits
less, and so on. But everyone except the last "warning shift is >= than
the width of the type". The same if I try with unsigned int.
If I try changing unchars by doubles, so they have the size I need for
the shifts and that warning cannot appear, but then "error using double
with int in binary >> operator". If I use with variables two doubles it
says the same error "using double with double in >> binary operator".
If I change to a struct with void varname:64; error because void is not
"forgotten" (I don't remember the exact word), or there is no cast to
int (in which case I have again the problem of shifting more than the
width of the type, I suppose, in the trial of this it still says error
because the buffer is void type or if I try int tal:64, then it exceeds
its type).
Finally, with temp as *unschar, the void_type{ int pues:64;}vacio;, I
read with temp, assign it with (int) cast to pues and shift pues it
reads it wrong and creates and error, windows has to close it.
With long double it says no more than 64 width bitfields.
Is there some way to do that and not having to be oneself who reads the
bits?
Here are the sizeofs of my computer:
char: 1
unsigned char: 1
unsigned long int: 4
short int: 2
short: 2
unsigned short int: 2
int: 4
float: 4
double: 8
unsigned char: 1
unsigned int: 4
long int: 4
long double: 12
The program:
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
#include <fstream.h>
#include <stdio.h>
typedef struct new_doble{
unsigned int dospri;
unsigned int dosult;
}doble;
typedef struct signed_doble{
int sig1;
int sig2;
}siged;
typedef struct novo_dos{
unsigned char uno;
unsigned char dos; //These two are from a trial with double, trying to
make a double with all 1 I get only 1.447e+09
unsigned char tres;
unsigned char cuatro;
unsigned char cinco;
unsigned char seis;
unsigned char siete;
unsigned char ocho;
}dos;
typedef struct complet{
double every;
};
typedef struct char_type{
unsigned char hype:64;
}extra;
typedef struct void_type{
int pues:64;//This was void in the previous trials
}vacio;
int main()
{
doble pares;
siged coplus;
dos octos;
complet all;
int pri, ult;
long double hala;
double tal;
double test = 747665.4576;
unsigned char mascara = 255;
short int mask = 65535;
int zorro = mask + (mask << 15);
double temp;
unsigned char *pol;
vacio nada;
extra largo;
fstream outFile;
fstream inFile;
FILE *fuera;
FILE *dentro;
cout << "zorro " << zorro << '\t' << mask << endl;
outFile.open("shifting", ios::out);
if(!outFile){
cout << "shifting no abre" << endl;
exit(1);
}
outFile << test;
outFile.close();
if((fuera = fopen("shifting", "r")) == NULL){
cout << "shiftin2 no abre" << endl;
exit(1);
}
fseek(fuera, 0, SEEK_END);
int size;
size = ftell(fuera);
rewind(fuera);
int tanto = 55;
while(!feof(fuera) && tanto >= 0){
fread(pol, 1, 8, fuera);
nada.pues=(int)pol;
tal = nada.pues << tanto;
tanto-=8;
}
fclose(fuera);
cout << test << '\n' << tal;
system("PAUSE");
return 0;
}
|
|
From: Luigi S. <gi...@li...> - 2002-06-08 16:22:50
|
At 00.48 06/08/02 +0000, chromatonus 712 wrote:
>Hi, here is my program that is suppose to read one piece of data from 2
>different sorted lists each,
>
>like these two text files:
>
>File A: 1 2 4 8 16
>File B: 0 1 1 2 3 5 8
>
>output should be
>File C: 0 1 1 1 2 2 3 4 5 8 8 16
>
>Would anyone give a sample program that performs this function, using only
>the "basic" file stream operations as in my program below? Thank you very much
>
>#include "apstring.h"
>#include <iostream.h>
>#include <fstream.h>
>#include <conio.h>
You are including too many things, the sole you need is:
#include <fstream>
If you plan to use the Dos function "pause", you should also include
"<cstdlib>". Note that if you run console programs from a console (I
recommend you do) there is no need for the line: system("pause"); which,
however, makes your code Dos / Windows specific.
>int main()
>{
> ifstream a; ifstream b;
> ofstream c;
> a.open("A.dat");
> b.open("B.dat");
Files may be attached to streams using the constructor:
std::ifstream a("A.dat");
std::ifstream b("B.dat");
std::ofstream c("C.dat");
> int ark, bum, j, k, temp;
> a >> ark;
> a.ignore(80,'\n');
> j = ark;
> b >> bum;
> b.ignore(80,'\n');
> k = bum;
> if( ark < bum )
> {
> c << ark << endl;
> a >> ark;
> a.ignore(80,'\n');
> temp = ark;
> }
> else
> {
> c << bum << endl;
> b >> bum;
> b.ignore(80,'\n');
> temp = bum;
> }
> if(j<k)
> {
> while( b>>bum && bum<temp )
> {
> b >> bum;
> b.ignore(80,'\n');
> c << bum << endl;
> b >> bum;
> b.ignore(80,'\n');
> }
> c << temp << endl;
> temp = bum;
> }
> else
> {
> while( a>>ark && ark<temp )
> {
> a >> ark;
> a.ignore(80,'\n');
> c << ark << endl;
> a >> ark;
> a.ignore(80,'\n');
> }
> c << temp << endl;
> temp = ark;
> }
The above code, is probably clearer this way:
int n1; // buffer for first stream
int n2; // buffer for second stream
a >> n1; // load buffers
b >> n2;
while (a && b)
if (n1 < n2) // print element of first list
{
c << n1 << ' ';
a >> n1; // load next element of first list
}
else // print element of second list
{
c << n2 << ' ';
b >> n2;
}
> while( c << temp )
> {
> cout << temp << endl;
> }
I don't understand what the above lines do (why are you printing on "c" and
then on the screen?), however, to complete the task, you should copy what
is left of the first or second stream, not forgetting to flush the buffer.
Here is what I mean:
if (a) // while-loop ended because second file exhausted
{
c << n1 << ' '; // flush buffer
copy(a, c); // copy the rest of the first list
}
else
{
c << n2 << ' ';
copy(b, c);
}
The function "copy" could be:
inline void
copy(std::istream is, std::ostream os)
{ int n; while (is >> n) os << n << ' '; }
> system("PAUSE");
> a.close();
> b.close();
> c.close();
>
>
> return 0;
None of these lines is really required. I've already explained the reason
why not to use"system", as far as file streams are concerned, the
destructor will take care of closing them. "return 0" is implicit.
>}
Putting pieces together and testing the program is your fun :)
NOTE: from the way you write include directives, I would say that you are
working with pre-ANSI C++. I strongly suggest you switch to ANSI C++ as
soon as you can.
--
Luigi
gi...@li...
|
|
From: Anita P. <lis...@bi...> - 2002-06-08 12:55:39
|
OK - I just realised that there _IS_ conio.h functionality in Dev-C++, but if you could see it in your hearts to show me where my inline assembler code is wrong I could at least fix my beloved getkey() function (provided I am not even more blind and missed that one too!) Cheers Stuart Downing |
|
From: Anita P. <lis...@bi...> - 2002-06-08 12:38:09
|
Hi folks, I have a problem for any of you inline assembler gurus:
I have been using DJGPP for years, and recently switched to Dev-C++ which I
instantly loved, but found
that a few functions I relied heavily on for console work don't exist:
clrscr, gotoxy, readkey and clreol.
I wrote using inline assembler within macros replacement functions which
compiled and ran fine on a copy of
DJGPP but upon using them in the MinGW compiler I get a weird problem.
Simply that it compiles without a
hitch (even with the -Wall switch) but upon running crashes after the very
first macro call.
I have included the clrscr() macro and a short version of my driver program
as an example hoping someone can point
me in the right direction. (Excuse the VERY primative debugging used, but I
haven't got the hang of most interactive
debuggers)
#define clrscr() \
asm("movw $0x0600, %ax \n\t" \
"movb $7, %bh \n\t" \
"movw $0x0000, %cx \n\t" \
"movw $0x184f, %dx \n\t" \
"int $0x10" );
int main(void)
{
FILE *smegfile;
int count;
char key;
#ifdef DEBUG
smegfile = fopen("smeg.txt", "wt");
fprintf(smegfile, "START\n");
fclose(smegfile);
#endif
clrscr();
#ifdef DEBUG
smegfile = fopen("smeg.txt", "wt");
fprintf(smegfile, "CLRSCR()\n");
fclose(smegfile);
#endif
return 0;
}
output in smeg.txt:
START
Cheers
Stuart Downing
|
|
From: Jason H. <jas...@nt...> - 2002-06-08 03:22:32
|
Quick tip:
get 'a'
get 'b'
repeat
if 'a' is greater than 'b'
output 'b'
get 'b'
else
output 'a'
get 'a'
until one of the streams is empty
This is a simplistic algorithm for you to follow, but it demonstrates the way two sorted streams can
be "merged" (lookup that word in an algorithms book). There is still one more thing for you to add:
When one of the streams runs out then you need to continue feeding from the other and outputing it
until it is also empty. And don't forget that the streams may be empty to start with! (tip: use a
while loop)
It would be wise for you to figure the rest out yourself, but one more tip: If you are repeating the
same steps several times in different places in a program, then it's a good idea to make those steps
into a function (i.e. getFromStream(); outputToStream();). Meaningful variable names also help
(instream_a, instream_b, outstream)
Jason.
PS: Not as quick a tip as I had planned, but at least I didn't hand everything to you on a plate.
----- Original Message -----
From: "chromatonus 712" <chr...@ho...>
To: <dev...@li...>
Sent: Saturday, June 08, 2002 1:48 AM
Subject: [Dev-C++] merging two sorted lists using file streams...
Hi, here is my program that is suppose to read one piece of data from 2
different sorted lists each,
like these two text files:
File A:
1
2
4
8
16
File B:
0
1
1
2
3
5
8
output should be
File C:
0 1 1 1 2 2 3 4 5 8 8 16
Would anyone give a sample program that performs this function, using only
the "basic" file stream operations as in my program below? Thank you very
much
#include "apstring.h"
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
int main()
{
ifstream a; ifstream b;
ofstream c;
a.open("A.dat");
b.open("B.dat");
int ark, bum, j, k, temp;
a >> ark;
a.ignore(80,'\n');
j = ark;
b >> bum;
b.ignore(80,'\n');
k = bum;
if( ark < bum )
{
c << ark << endl;
a >> ark;
a.ignore(80,'\n');
temp = ark;
}
else
{
c << bum << endl;
b >> bum;
b.ignore(80,'\n');
temp = bum;
}
if(j<k)
{
while( b>>bum && bum<temp )
{
b >> bum;
b.ignore(80,'\n');
c << bum << endl;
b >> bum;
b.ignore(80,'\n');
}
c << temp << endl;
temp = bum;
}
else
{
while( a>>ark && ark<temp )
{
a >> ark;
a.ignore(80,'\n');
c << ark << endl;
a >> ark;
a.ignore(80,'\n');
}
c << temp << endl;
temp = ark;
}
while( c << temp )
{
cout << temp << endl;
}
system("PAUSE");
a.close();
b.close();
c.close();
return 0;
}
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
_______________________________________________________________
Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas - http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Ioannis V. <no...@ho...> - 2002-06-08 02:45:30
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Mac Reiter > Sent: Thursday, June 06, 2002 12:00 AM > To: Dev-C++ User Mailing List > Subject: Re: [Dev-C++] #include <ios> > > > Daniel: > > The <ios> header is generally not needed, and should have > been included by > other iostreams headers. I suspect that the GCC or MinGW > people simply > removed the standalone header, or perhaps it is present but > can only be > found if you specify <ios.h> instead of just <ios>. (The <ios.h> is > *purely* a guess and I haven't run any checks at all). Since > Dev-C++ is > "just" the editor/debugger/project manager, and it uses the GCC/MinGW > toolchain for actual compilation, these kinds of issues will depend > entirely on how the GCC/MinGW tools work. > <ios> is needed when you want to use the facilities icnluded in it. You can not depend if a header file is included in another when not defined by the standard (if you wat the code to be portable, not even among different compilers and platforms, but even to the next version of your favorite compiler). You *must not* care about implementation details inside your code, and certainly not connect your code with them. It is the compiler's job for what headers it #include s inside other header files. > Microsoft's take on <ios> is given in the following MSDN article: > > http://msdn.microsoft.com/library/default.asp?url=/library/en- > us/vcstdlib/ht > ml/vclrfios_header.asp > > Basically, you could simply remove the <ios> line entirely, and both > compilers would be happy and you wouldn't need the > preprocessor commands > ("ifndef", etc). I'm gonna guess that the book was written > some time ago, > some of the C++ standards changed along the way, and not all > of the sample > code got updated. No the book is ANSI C++ compliant (at least as far as i know, and C++ god approves it, and god only approves excellent ANSI C++ compliant books). > > **IMPORTANT NOTE FOR NEW C++ PROGRAMMERS ** > Also, there is no such thing as an "ANSI C++ compliant > compiler" Of course there is. Try Intel C++ compiler for example. > -- *all* > current compilers fail the conformance tests in various ways. Not all. And standard conformance is increased day by day to the rest compilers too. Camaeu is another 100% conformant compiler too. And there are probably others too (perhaps GCC 3.x is 100% compliant too). > This means > that sample code inevitably needs to be modified for > different compilers. Things are improving day by day. The standard is very recent (late of 1998) for *everything* to be implemented immediately. And C++ is a multiparadigm language, that means it is like 4+ languages together (4 paradigms and many space/time efficiency concerns since it is intended for mission critical applications too (OSes, etc). > "Portable" code, for the time being, requires preprocessor > directives like > the one shown to change the code based on which compiler is > being used. No. Simply you code for the compiler you intend to use thinking of full ansi C++ and then if something does not compile, you change it with something that does. If you write a library or something and you care for many compilers out there, i wouldn't care but code as freely as i can knowing that since things are improving day by day everything will be soon ok for them too. That is, i can't think of an occasion why i would need #ifndefs for portability, and i can't think for any possible reason to do so. #ifndefs are used to make portable code using compiler extensions not for ANSI C++ code.Ioannis I think you have confused ANSI C++ code with system specific code (e.g. Win32 library calls). * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys |
|
From: Ioannis V. <no...@ho...> - 2002-06-08 02:29:59
|
> -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Bob Wilson > Sent: Thursday, June 06, 2002 3:33 AM > To: Dev-C++ User Mailing List > Subject: Re: [Dev-C++] #include <ios> > > > **IMPORTANT NOTE FOR NEW C++ PROGRAMMERS ** > > Also, there is no such thing as an "ANSI C++ compliant > compiler" -- *all* > > current compilers fail the conformance tests in various > ways. This means > > that sample code inevitably needs to be modified for > different compilers. > > For the simplist programs, however, there should not be any > modifications > required. Just out of curiosity, do you know of a "knowledge > base" that > summarizes the changes that are often reuired from compiler > to compiler? Not for the simplest only. There is no need for such a knowledge base, because ANSI C++ conformance will be improving continually. Do not think that there will remain gray areas at the end, as for ANSI SQL conformance for example. There are already compilers with 100% conformance. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys |
|
From: chromatonus 7. <chr...@ho...> - 2002-06-08 00:48:52
|
Hi, here is my program that is suppose to read one piece of data from 2
different sorted lists each,
like these two text files:
File A:
1
2
4
8
16
File B:
0
1
1
2
3
5
8
output should be
File C:
0 1 1 1 2 2 3 4 5 8 8 16
Would anyone give a sample program that performs this function, using only
the "basic" file stream operations as in my program below? Thank you very
much
#include "apstring.h"
#include <iostream.h>
#include <fstream.h>
#include <conio.h>
int main()
{
ifstream a; ifstream b;
ofstream c;
a.open("A.dat");
b.open("B.dat");
int ark, bum, j, k, temp;
a >> ark;
a.ignore(80,'\n');
j = ark;
b >> bum;
b.ignore(80,'\n');
k = bum;
if( ark < bum )
{
c << ark << endl;
a >> ark;
a.ignore(80,'\n');
temp = ark;
}
else
{
c << bum << endl;
b >> bum;
b.ignore(80,'\n');
temp = bum;
}
if(j<k)
{
while( b>>bum && bum<temp )
{
b >> bum;
b.ignore(80,'\n');
c << bum << endl;
b >> bum;
b.ignore(80,'\n');
}
c << temp << endl;
temp = bum;
}
else
{
while( a>>ark && ark<temp )
{
a >> ark;
a.ignore(80,'\n');
c << ark << endl;
a >> ark;
a.ignore(80,'\n');
}
c << temp << endl;
temp = ark;
}
while( c << temp )
{
cout << temp << endl;
}
system("PAUSE");
a.close();
b.close();
c.close();
return 0;
}
_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
|
|
From: Ioannis V. <no...@ho...> - 2002-06-07 22:30:47
|
And the release notes for the MINGW GCC 3.1: http://sourceforge.net/project/shownotes.php?release_id=90000 Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net <http://www.noicys.cjb.net/> * Alternative URL: http://run.to/noicys |
|
From: Ioannis V. <no...@ho...> - 2002-06-07 22:13:27
|
I decided to take a look at MINGW site and saw that there are recent
distributions of many components of MINGW including a GCC 3.1 release!
But there is not yet a newest "official" distribution of MINGW yet
(there is still the classic 1.1 of 2001 release). However i have the
feeling that one is about to come soon (but "soon" can be even months).
Anyway for all coders out there who can handle this kind of things, can
download the latest GCC 3.1 core distribution and the latest MINGW run
time, and uncompress them above their current MINGW distribution.
As expected the latest GCC is far more compliant than the 2.x series so
the code below compiles happily:
#include <vector>
#include <iostream>
#include <stdexcept>
int main() try
{
using namespace std;
vector<int>array(50);
for(unsigned i=0; i<100; i++)
cout<<(array.at(i)=i)<<" ";
}
catch(std::out_of_range)
{
std::cout<<"\n\nBe careful dude! What are you doing dude?\n";
}
But before you decide to do the hack update, be careful that you must
know what you are doing. If you do not know how to do this kind of
things then wait for the official MINGW distribution when it becomes
available, or the Dev-C++ version that will include it.
What i have done (not tested with Dev-C++):
1) I downloaded the files
http://telia.dl.sourceforge.net/sourceforge/mingw/gcc-3_1-core-20020516-
1.tar.gz
(about 600k)
http://telia.dl.sourceforge.net/sourceforge/mingw/mingw-runtime-2.0-2002
0430.tar.gz
(about 10 MB)
2) I uncompressed the first on a temporary empty folder and then cut &
paste above my old MINGW distribution.
Then i uncompressed the second on the temporary empty folder and then
cut & paste above my old MINGW distribution.
3) Everything works happily:
C:\>g++ -v
Reading specs from c:/mingw/bin/../lib/gcc-lib/mingw32/3.1/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as
--host=
mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls
--enable
-languages=f77,c++,objc,ada --disable-win32-registry --disable-shared
Thread model: win32
gcc version 3.1
C:\>gcc -v
Reading specs from c:/mingw/bin/../lib/gcc-lib/mingw32/3.1/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as
--host=
mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls
--enable
-languages=f77,c++,objc,ada --disable-win32-registry --disable-shared
Thread model: win32
gcc version 3.1
C:\c>g++ temp.cpp -o temp -ansi -pedantic-errors -Wall
-fexpensive-optimizations
-O3 -ffloat-store -mcpu=pentiumpro
C:\c>temp
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
Be careful dude! What are you doing dude?
C:\c>
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
<http://www.noicys.cjb.net/>
* Alternative URL: http://run.to/noicys
|
|
From: Luigi S. <gi...@li...> - 2002-06-07 15:01:23
|
At 22:23 06/06/02 -0300, Juliano P=E1vel Brasil Cust=F3dio wrote: > Rob, I didn't got any error message when I tried to compile and >run your program. By the way, I'm working with an Athlon >800MHz/WinXP/DevCpp 4.9.3.0. Probably you had warnings turned off. BTW: did the program exhibit the=20 strange behavior reported by Rob? -- Luigi gi...@li... |
|
From: Luigi S. <gi...@li...> - 2002-06-07 15:01:00
|
At 15:07 06/06/02 -0700, rchavez wrote:
>Hi,
>
>While trying a problem from my text 'A Book on C' I ran into some strange
>behavior for short integers. If I use integers, the program below reads
>them in & performs the arithmetic correctly. But if I change line 3 so the
>variables are of type short, the value of x is always 0 !!
>...
The reason, I guess, is that you are reading integers using the wrong
format, in fact, you read a short using "%d", instead of "%hd". I'm not an
expert, hopefully someone else can fill the details, so I'll say it simple:
you are "trying to put a round peg in a square hole" :).
I modified your code (hope you don't mind :), to isolate what seems the
"strange" behavior. Below is the result.
file: test.c
-------------
#include <stdio.h>
/*********************************************************************
Parametrize the type of integer used by the program
possible values are:
short
int
long
*********************************************************************/
#define INTEGER short
/*********************************************************************
How should an INTEGER be scanned or printed
The format should be chosen according to what is used for INTEGER,
thus values are:
short "%hd"
int "%d"
long "%ld"
If you mix, that is, setting INTEGER to short and using "%d" as
FORMAT; when compiling, expect to see, at least, a warning.
*********************************************************************/
#define FORMAT "%d"
/*********************************************************************
test - try to scan / print different types of integers
The program expects input from the console.
*********************************************************************/
int
main()
{
INTEGER i;
INTEGER j;
/* tell what is currently used for INTEGERS */
printf("sizeof(INTEGER):\t%d bytes\n",sizeof(INTEGER));
printf("format to scan/print:\t%s\n\n", FORMAT);
printf("Enter an INTEGER:\t");
scanf(FORMAT, &i); /* this is the offending line (it is #50) */
printf("you just entered:\t" FORMAT "\n\n", i);
printf("Enter another INTEGER:\t");
scanf(FORMAT, &j); /* the other offending line (it is #54) */
printf("you just entered:\t" FORMAT "\n\n", j);
printf("Simple operation using INTEGERS:\n");
printf("i = " FORMAT "\tj = " FORMAT "\n", i, j); /* surprise! */
printf("i + j = %d\n", i + j);
return 0;
}
-------------
I've generated a binary file using different compilers, here are the results:
*) Borland Turbo C++ version 1.01 (very old compiler, I use it for C only)
command: tcc -w test.c
results: no warning was emitted, executable works! No "strange" behavior
*) Borland C++ 5.5.1 (free command line tools):
command: bcc32 -w test.c
results: no warning was emitted, but executable exhibits the "strange"
behavior
*) GNU gcc 2.95.2 (Win98SE - MinGW)
command: gcc -Wall test.c
results: warnings emitted and executable exhibits the "strange" behavior
warning messages:
-----------------
test.c: In function `main':
test.c:50: warning: int format, different type arg (arg 2)
test.c:54: warning: int format, different type arg (arg 2)
One last thing: a C++ version of the program that uses stream extraction
operator, would have no problem. If you are allowed, switch to C++.
Regards
--
Luigi
gi...@li...
|
|
From: Jonathan R. <jon...@tr...> - 2002-06-07 13:51:46
|
how do i link to dll's in dev-c++. i cant find infoz thanks - jonathan |
|
From: Bob W. <bo...@ph...> - 2002-06-07 13:19:44
|
Matt, >> however, I'm at a loss regarding how to track these things down. << There are serveral things you can do. 1. Make sure you delete any pointers when you are finished with them. 2. Try like the devil not to use any global pointers. 3. Make full use of whatever debugging factilities provided with your compiler, i.e., "assert()", liberal sprinkling of debugging precompiler macros to examin intermediate values, and use of "try" and "catch" blocks around all I/O and memory management routines. 4. Step through the code one line at a time with your debugger so you can identify exactly where the program is blowing up. This fourth step is best accomplished by using whatever input you know blows the program up early, and it would be best to use several different short time blow-ups to ensure the problem is happening at the same place. Good luck! Bob |
|
From: Ioannis V. <no...@ho...> - 2002-06-07 13:03:24
|
I think that the linux version was abandoned. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys > -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf > Of Massmiliano Cialdi > Sent: Thursday, June 06, 2002 3:28 PM > To: dev...@li... > Subject: [Dev-C++] linux version > > > I notice that the windows version of DEV-C++ is 4.9.3.0 > and the linux one is 0.7.0 > > I wonder if the linux version is still developed. > > thanks > -- > Massimiliano Cialdi > ci...@co... > ci...@fi... > > _______________________________________________________________ > > Don't miss the 2002 Sprint PCS Application Developer's Conference > August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm > > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Ioannis V. <no...@ho...> - 2002-06-07 13:02:55
|
Also in my system, short ss was too small to store 64000 and the results got truncated. That's why i made it int. Ioannis * Ioannis Vranos * Programming pages: http://www.noicys.cjb.net * Alternative URL: http://run.to/noicys > -----Original Message----- > From: Ioannis Vranos [mailto:no...@ho...]=20 > Sent: Friday, June 07, 2002 3:59 PM > To: Dev-C++ Mailing List > Subject: RE: [Dev-C++] short integer problem >=20 >=20 > Yes it has the bug, because he used wrong format specifiers. For short > he should use %hd. Also in a variadic function, when the=20 > passed type is > different from the type specifier a casting should be used (e.g. > printf("\n sizeof(short): %d",(int)sizeof(short)); ). >=20 >=20 > #include <stdio.h> > #include <stdlib.h> >=20 >=20 > int main(void) > { > short x,y, entries; /* declared as int program works as > expected */ > int ss; > printf("\n sizeof(short): %d",(int)sizeof(short)); > printf("\n2 to the 15: %d\n\n",128*128*2); > printf("\n Enter 2 int values: \n"); > entries=3Dscanf("%hd",&x); > entries +=3Dscanf("%hd",&y); > printf("\n x=3D %hd y=3D %hd",x,y); >=20 > while (entries =3D=3D 2) { > printf("\n x=3D %hd y=3D %hd",x,y); > printf("\nX+Y =3D %hd",x+y); > printf("\nX-Y =3D %hd",x-y); > printf("\nX*Y =3D %hd",x*y); > printf("\nX/Y =3D %hd",x/y); > printf("\nx %c y =3D %hd\n",'\045',x%y); >=20 > ss =3D 64000; > printf("\nEnter a short int"); > scanf("%d",&ss); > printf("\n Another try on a short int gives: %d",ss); > printf("\n Enter 2 int values: "); > entries=3Dscanf("%hd%hd",&x,&y); > } >=20 > printf("\n\n"); > system("PAUSE"); > return 0; > } >=20 >=20 >=20 >=20 >=20 >=20 > Ioannis >=20 > * Ioannis Vranos > * Programming pages: http://www.noicys.cjb.net > * Alternative URL: http://run.to/noicys >=20 >=20 > > -----Original Message----- > > From: dev...@li...=20 > > [mailto:dev...@li...] On Behalf=20 > > Of Juliano P=E1vel Brasil Cust=F3dio > > Sent: Friday, June 07, 2002 4:23 AM > > To: dev...@li... > > Subject: RE: [Dev-C++] short integer problem > >=20 > >=20 > > Rob, I didn't got any error message when I tried to compile and > > run your program. By the way, I'm working with an Athlon > > 800MHz/WinXP/DevCpp 4.9.3.0. > >=20 > > Juliano > >=20 > > -----Original Message----- > > From: dev...@li... > > [mailto:dev...@li...] On Behalf=20 > > Of rchavez > > Sent: quinta-feira, 6 de junho de 2002 19:08 > > To: dev...@li... > > Subject: [Dev-C++] short integer problem > >=20 > >=20 > > Hi, > >=20 > > While trying a problem from my text 'A Book on C' I ran into some > > strange behavior for short integers. If I use integers, the program > > below reads them in & performs the arithmetic correctly. But if I > > change line 3 so the variables are of type short, the value of x is > > always 0 !! > >=20 > > I've played with it a lot but can't find the problem. Any=20 > > help would be > > appreciated. Also, notice that the scanf for var ss at the bottom > > always works. It's not a gcc bug since I get the same behavior on a > > unix compiler. > >=20 > > Rob > >=20 > > /** Math on Short Integers **/ > >=20 > > main() > > { > > short x,y, entries=3D2; /* declared as int program works as > > expected */ > > short ss; > > printf("\n sizeof(short): %d",sizeof(short)); > > printf("\n2 to the 15: %d\n\n",128*128*2); > > printf("\n Enter 2 int values: \n"); > > entries=3Dscanf("%d",&x); > > entries +=3Dscanf("%d",&y); > > printf("\n x=3D %d y=3D %d",x,y); > >=20 > > while (entries =3D=3D 2) { > > printf("\n x=3D %d y=3D %d",x,y); > > printf("\nX+Y =3D %d",x+y); > > printf("\nX-Y =3D %d",x-y); > > printf("\nX*Y =3D %d",x*y); > > printf("\nX/Y =3D %d",x/y); > > printf("\nx %c y =3D %d\n",'\045',x%y); > >=20 > > ss =3D 64000; > > printf("\nEnter a short int"); > > scanf("%d",&ss); > > printf("\n Another try on a short int gives: %d",ss); > > printf("\n Enter 2 int values: "); > > entries=3Dscanf("%d%d",&x,&y); > > } > >=20 > > printf("\n\n"); > > system("PAUSE"); > > return 0; > > } > >=20 > > _______________________________________________________________ > >=20 > > Don't miss the 2002 Sprint PCS Application Developer's=20 > > Conference August > > 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm > >=20 > > _______________________________________________ > > Dev-cpp-users mailing list > > Dev...@li... > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > >=20 > >=20 > > _______________________________________________________________ > >=20 > > Don't miss the 2002 Sprint PCS Application Developer's Conference > > August 25-28 in Las Vegas --=20 > http://devcon.sprintpcs.com/adp/index.cfm > >=20 > >=20 > _______________________________________________ > > Dev-cpp-users mailing list > > Dev...@li... > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > >=20 >=20 |
|
From: Ioannis V. <no...@ho...> - 2002-06-07 12:59:40
|
Yes it has the bug, because he used wrong format specifiers. For short
he should use %hd. Also in a variadic function, when the passed type is
different from the type specifier a casting should be used (e.g.
printf("\n sizeof(short): %d",(int)sizeof(short)); ).
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
short x,y, entries; /* declared as int program works as
expected */
int ss;
printf("\n sizeof(short): %d",(int)sizeof(short));
printf("\n2 to the 15: %d\n\n",128*128*2);
printf("\n Enter 2 int values: \n");
entries=3Dscanf("%hd",&x);
entries +=3Dscanf("%hd",&y);
printf("\n x=3D %hd y=3D %hd",x,y);
while (entries =3D=3D 2) {
printf("\n x=3D %hd y=3D %hd",x,y);
printf("\nX+Y =3D %hd",x+y);
printf("\nX-Y =3D %hd",x-y);
printf("\nX*Y =3D %hd",x*y);
printf("\nX/Y =3D %hd",x/y);
printf("\nx %c y =3D %hd\n",'\045',x%y);
ss =3D 64000;
printf("\nEnter a short int");
scanf("%d",&ss);
printf("\n Another try on a short int gives: %d",ss);
printf("\n Enter 2 int values: ");
entries=3Dscanf("%hd%hd",&x,&y);
}
printf("\n\n");
system("PAUSE");
return 0;
}
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.cjb.net
* Alternative URL: http://run.to/noicys
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Juliano P=E1vel Brasil Cust=F3dio
> Sent: Friday, June 07, 2002 4:23 AM
> To: dev...@li...
> Subject: RE: [Dev-C++] short integer problem
>=20
>=20
> Rob, I didn't got any error message when I tried to compile and
> run your program. By the way, I'm working with an Athlon
> 800MHz/WinXP/DevCpp 4.9.3.0.
>=20
> Juliano
>=20
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf=20
> Of rchavez
> Sent: quinta-feira, 6 de junho de 2002 19:08
> To: dev...@li...
> Subject: [Dev-C++] short integer problem
>=20
>=20
> Hi,
>=20
> While trying a problem from my text 'A Book on C' I ran into some
> strange behavior for short integers. If I use integers, the program
> below reads them in & performs the arithmetic correctly. But if I
> change line 3 so the variables are of type short, the value of x is
> always 0 !!
>=20
> I've played with it a lot but can't find the problem. Any=20
> help would be
> appreciated. Also, notice that the scanf for var ss at the bottom
> always works. It's not a gcc bug since I get the same behavior on a
> unix compiler.
>=20
> Rob
>=20
> /** Math on Short Integers **/
>=20
> main()
> {
> short x,y, entries=3D2; /* declared as int program works as
> expected */
> short ss;
> printf("\n sizeof(short): %d",sizeof(short));
> printf("\n2 to the 15: %d\n\n",128*128*2);
> printf("\n Enter 2 int values: \n");
> entries=3Dscanf("%d",&x);
> entries +=3Dscanf("%d",&y);
> printf("\n x=3D %d y=3D %d",x,y);
>=20
> while (entries =3D=3D 2) {
> printf("\n x=3D %d y=3D %d",x,y);
> printf("\nX+Y =3D %d",x+y);
> printf("\nX-Y =3D %d",x-y);
> printf("\nX*Y =3D %d",x*y);
> printf("\nX/Y =3D %d",x/y);
> printf("\nx %c y =3D %d\n",'\045',x%y);
>=20
> ss =3D 64000;
> printf("\nEnter a short int");
> scanf("%d",&ss);
> printf("\n Another try on a short int gives: %d",ss);
> printf("\n Enter 2 int values: ");
> entries=3Dscanf("%d%d",&x,&y);
> }
>=20
> printf("\n\n");
> system("PAUSE");
> return 0;
> }
>=20
> _______________________________________________________________
>=20
> Don't miss the 2002 Sprint PCS Application Developer's=20
> Conference August
> 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm
>=20
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>=20
>=20
> _______________________________________________________________
>=20
> Don't miss the 2002 Sprint PCS Application Developer's Conference
> August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm
>=20
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>=20
|
|
From: <jar...@ig...> - 2002-06-07 11:59:20
|
On 6 Jun, rchavez wrote:
> Hi,
>
> While trying a problem from my text 'A Book on C' I ran into some strange
> behavior for short integers. If I use integers, the program below reads
> them in & performs the arithmetic correctly. But if I change line 3 so the
> variables are of type short, the value of x is always 0 !!
>
> I've played with it a lot but can't find the problem. Any help would be
> appreciated. Also, notice that the scanf for var ss at the bottom always
> works. It's not a gcc bug since I get the same behavior on a unix compiler.
>
> Rob
>
> /** Math on Short Integers **/
>
> main()
> {
> short x,y, entries=2; /* declared as int program works as expected */
> short ss;
> printf("\n sizeof(short): %d",sizeof(short));
> printf("\n2 to the 15: %d\n\n",128*128*2);
> printf("\n Enter 2 int values: \n");
> entries=scanf("%d",&x);
====================^^ ^
Since x is of type short int you MUST you the input format
%hd . If you write %d scanf inputs 4 bytes and thus overwrites the
2 bytes in storage following x .
Since scanf use a variable parameter list type checking is disabled.
One more reason to avoid the C input/output system.
In C++ the input operator '>>' has no such problems.
The same in the scanf calls below.
> entries +=scanf("%d",&y);
> printf("\n x= %d y= %d",x,y);
>
> while (entries == 2) {
> printf("\n x= %d y= %d",x,y);
> printf("\nX+Y = %d",x+y);
> printf("\nX-Y = %d",x-y);
> printf("\nX*Y = %d",x*y);
> printf("\nX/Y = %d",x/y);
> printf("\nx %c y = %d\n",'\045',x%y);
>
> ss = 64000;
> printf("\nEnter a short int");
> scanf("%d",&ss);
> printf("\n Another try on a short int gives: %d",ss);
> printf("\n Enter 2 int values: ");
> entries=scanf("%d%d",&x,&y);
> }
>
> printf("\n\n");
> system("PAUSE");
> return 0;
> }
>
--
Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
Institute of Technology, RWTH Aachen
D 52056 Aachen, Germany
|