Thread: [Dev-C++] redeclaration of built in type 'bool'
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Mux0x55 o. a u. <mu...@gm...> - 2007-05-06 22:36:40
|
Good evening @ all, I have a big problem. I want to use DevCpp to compile C progs only, but I can't compile because it gives me this compilation error: "redeclaration of built in type bool". How can I solve the problem? Is there a method to disable c++ compiler ? Help me please. I'm a student of IT Engineering and I'm using the Roberts library of "Programming with abstractions in C" . I have to use the devCpp and I have to use these libraries. Help me again. Thank You. |
|
From: Jonathan W. <jon...@gm...> - 2007-05-07 00:57:10
|
When you create the project you put the code in, you should select the language to use (bottom-right of the dialog) Also, in Project Options > Files, you can change the settings on a file-by-file basis. Happy coding :) Jonathan On 5/7/07, Mux0x55 otto a uno <mu...@gm...> wrote: > > Good evening @ all, > I have a big problem. I want to use DevCpp to compile C progs only, but I > can't compile because it gives me this compilation error: "redeclaration of > built in type bool". How can I solve the problem? Is there a method to > disable c++ compiler ? Help me please. I'm a student of IT Engineering and > I'm using the Roberts library of "Programming with abstractions in C" . > I have to use the devCpp and I have to use these libraries. Help me again. > Thank You. > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > -- <Morpheus> linux, c'est une question de VI ou de MORE |
|
From: Jan M. <jan...@vo...> - 2007-05-07 06:26:11
|
Hello, I would like to compare an integer with a string using strcmp(). So I need to cast the int type to string (*char). Is there some commone way how to do it. Should I use & operator and adress of int in teh function? Or something else? Thank you very much Jan Mura |
|
From: Per W. <pw...@ia...> - 2007-05-07 06:34:40
|
You can't cast an int to string, and you cant cast a string to an integer. Either use strtol(), atoi() or similar to convert the string to an integer, or use sprintf() or similar to convert the integer to a string. /pwm On Mon, 7 May 2007, Jan Mura wrote: > Hello, > > I would like to compare an integer with a string using strcmp(). So I need > to cast the int type to string (*char). Is there some commone way how to do > it. Should I use & operator and adress of int in teh function? Or something > else? > > Thank you very much > > Jan Mura > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Philip B. <phi...@pb...> - 2007-05-07 06:35:10
|
This will do the job. char outputstring[32]; sprintf(outputstring, "%d", integer); It basically prints your integer into the character array, as long as there is enough space to hold it. This method works both in C and C++. There are other methods such as stringstream, but they only work in C++. If you're compiling a C program, for this function to work you need to include stdio.h and for C++ it is cstdio. Regards Philip Bennefall ----- Original Message ----- From: "Jan Mura" <jan...@vo...> To: <dev...@li...> Sent: Monday, May 07, 2007 8:26 AM Subject: [Dev-C++] Casting of int to string > Hello, > > I would like to compare an integer with a string using strcmp(). So I need > to cast the int type to string (*char). Is there some commone way how to > do > it. Should I use & operator and adress of int in teh function? Or > something > else? > > Thank you very much > > Jan Mura > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Jonathan W. <jon...@gm...> - 2007-05-07 07:08:33
|
Just a note: """ It basically prints your integer into the character array, as long as there is enough space to hold it """ Actually it will print the integer whether there is enough space or not.. It is entirely Your job to make sure there is enough space, or else sprintf will just keep on printing in memory after the end of the array. Obviously this is a very bad idea, since there is other data there. In this case, determining the necessary space is as easy as 'what's the maximum digit count in an integer'... but in other cases, you can get wierd crashes, wrong data for no apparent reason, or even create an exploit in your program. Thought you might want to know that (and if you did, no offense intended :) Jonathan On 5/7/07, Philip Bennefall <phi...@pb...> wrote: > > This will do the job. > char outputstring[32]; > sprintf(outputstring, "%d", integer); > > It basically prints your integer into the character array, as long as > there > is enough space to hold it. This method works both in C and C++. There are > other methods such as stringstream, but they only work in C++. If you're > compiling a C program, for this function to work you need to include > stdio.h > and for C++ it is cstdio. > > Regards > Philip Bennefall > ----- Original Message ----- > From: "Jan Mura" <jan...@vo...> > To: <dev...@li...> > Sent: Monday, May 07, 2007 8:26 AM > Subject: [Dev-C++] Casting of int to string > > > > Hello, > > > > I would like to compare an integer with a string using strcmp(). So I > need > > to cast the int type to string (*char). Is there some commone way how to > > do > > it. Should I use & operator and adress of int in teh function? Or > > something > > else? > > > > Thank you very much > > > > Jan Mura > > > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by DB2 Express > > Download DB2 Express C - the FREE version of DB2 express and take > > control of your XML. No limits. Just data. Click to get it now. > > http://sourceforge.net/powerbar/db2/ > > _______________________________________________ > > Dev-cpp-users mailing list > > Dev...@li... > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > -- <Morpheus> linux, c'est une question de VI ou de MORE |
|
From: Philip B. <phi...@pb...> - 2007-05-07 07:30:39
|
Sorry, I should've phrased it differently. Yup, allocating too little =
memory is a bad idea in any situation because the function has no way of =
knowing when it is supposed to stop writing. I just put 32 in there =
because it ensures (100 %) that the entire value will be stored =
including the Null terminator.
Regards
Philip Bennefall
----- Original Message -----=20
From: Jonathan Winterflood=20
To: Jan Mura=20
Cc: dev...@li...=20
Sent: Monday, May 07, 2007 9:08 AM
Subject: Re: [Dev-C++] Casting of int to string
Just a note:
""" It basically prints your integer into the character array, as long =
as there is enough space to hold it """
Actually it will print the integer whether there is enough space or =
not.. It is entirely Your job to make sure there is enough space, or =
else sprintf will just keep on printing in memory after the end of the =
array. Obviously this is a very bad idea, since there is other data =
there.=20
In this case, determining the necessary space is as easy as 'what's =
the maximum digit count in an integer'... but in other cases, you can =
get wierd crashes, wrong data for no apparent reason, or even create an =
exploit in your program.=20
Thought you might want to know that (and if you did, no offense =
intended :)
Jonathan
On 5/7/07, Philip Bennefall < phi...@pb...> wrote:
This will do the job.
char outputstring[32];
sprintf(outputstring, "%d", integer);
It basically prints your integer into the character array, as long =
as there
is enough space to hold it. This method works both in C and C++. =
There are=20
other methods such as stringstream, but they only work in C++. If =
you're
compiling a C program, for this function to work you need to include =
stdio.h
and for C++ it is cstdio.
Regards
Philip Bennefall=20
----- Original Message -----
From: "Jan Mura" <jan...@vo...>
To: <dev...@li... >
Sent: Monday, May 07, 2007 8:26 AM
Subject: [Dev-C++] Casting of int to string
> Hello,
>
> I would like to compare an integer with a string using strcmp(). =
So I need
> to cast the int type to string (*char). Is there some commone way =
how to=20
> do
> it. Should I use & operator and adress of int in teh function? Or
> something
> else?
>
> Thank you very much
>
> Jan Mura
>
>
> =
-------------------------------------------------------------------------=
=20
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...=20
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users=20
>
=
-------------------------------------------------------------------------=
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.=20
http://sourceforge.net/powerbar/db2/
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
--=20
<Morpheus> linux, c'est une question de VI ou de MORE=20
-------------------------------------------------------------------------=
-----
=
-------------------------------------------------------------------------=
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
-------------------------------------------------------------------------=
-----
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
|
|
From: Per W. <pw...@ia...> - 2007-05-07 08:22:29
|
Better C libraries have the snprintf() function, that takes the size of the buffer as an input parameter. /pwm On Mon, 7 May 2007, Philip Bennefall wrote: > Sorry, I should've phrased it differently. Yup, allocating too little memory is a bad idea in any situation because the function has no way of knowing when it is supposed to stop writing. I just put 32 in there because it ensures (100 %) that the entire value will be stored including the Null terminator. > > Regards > Philip Bennefall > ----- Original Message ----- > From: Jonathan Winterflood > To: Jan Mura > Cc: dev...@li... > Sent: Monday, May 07, 2007 9:08 AM > Subject: Re: [Dev-C++] Casting of int to string > > > Just a note: > """ It basically prints your integer into the character array, as long as there is enough space to hold it """ > Actually it will print the integer whether there is enough space or not.. It is entirely Your job to make sure there is enough space, or else sprintf will just keep on printing in memory after the end of the array. Obviously this is a very bad idea, since there is other data there. > In this case, determining the necessary space is as easy as 'what's the maximum digit count in an integer'... but in other cases, you can get wierd crashes, wrong data for no apparent reason, or even create an exploit in your program. > > Thought you might want to know that (and if you did, no offense intended :) > Jonathan > > > On 5/7/07, Philip Bennefall < phi...@pb...> wrote: > This will do the job. > char outputstring[32]; > sprintf(outputstring, "%d", integer); > > It basically prints your integer into the character array, as long as there > is enough space to hold it. This method works both in C and C++. There are > other methods such as stringstream, but they only work in C++. If you're > compiling a C program, for this function to work you need to include stdio.h > and for C++ it is cstdio. > > Regards > Philip Bennefall > ----- Original Message ----- > From: "Jan Mura" <jan...@vo...> > To: <dev...@li... > > Sent: Monday, May 07, 2007 8:26 AM > Subject: [Dev-C++] Casting of int to string > > > > Hello, > > > > I would like to compare an integer with a string using strcmp(). So I need > > to cast the int type to string (*char). Is there some commone way how to > > do > > it. Should I use & operator and adress of int in teh function? Or > > something > > else? > > > > Thank you very much > > > > Jan Mura > > > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by DB2 Express > > Download DB2 Express C - the FREE version of DB2 express and take > > control of your XML. No limits. Just data. Click to get it now. > > http://sourceforge.net/powerbar/db2/ > > _______________________________________________ > > Dev-cpp-users mailing list > > Dev...@li... > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > -- > <Morpheus> linux, c'est une question de VI ou de MORE > > > ------------------------------------------------------------------------------ > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > > > ------------------------------------------------------------------------------ > > > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Jan M. <jan...@vo...> - 2007-05-07 09:21:26
|
Thank you, it came to my mind what about the NULL character at the end of
the string.
Maybe one more thing. I am not sure if my code is ok because of the similar
reasons about some illegal memory usage.
So I have something like
struct bet_list
{
int id;
char *name;
struct bet_list *next;
};
...
struct bet_list *member, *temp;
member = malloc(sizeof(struct bet_list));
member->id = 1;
strcpy(member->name, "some string here");
member->next = NULL;
...
I am not sure if malloc allocates enough space if it dont know how long is a
string I would like to put in.
Thanks again
Jan Mura
---- Original Message -----
From: "Per Westermark" <pw...@ia...>
To: "Philip Bennefall" <phi...@pb...>
Cc: "Jonathan Winterflood" <jon...@gm...>; "Jan Mura"
<jan...@vo...>; <dev...@li...>
Sent: Monday, May 07, 2007 10:21 AM
Subject: Re: [Dev-C++] Casting of int to string
> Better C libraries have the snprintf() function, that takes the size of
> the buffer as an input parameter.
>
> /pwm
>
> On Mon, 7 May 2007, Philip Bennefall wrote:
>
> > Sorry, I should've phrased it differently. Yup, allocating too little
memory is a bad idea in any situation because the function has no way of
knowing when it is supposed to stop writing. I just put 32 in there because
it ensures (100 %) that the entire value will be stored including the Null
terminator.
> >
> > Regards
> > Philip Bennefall
> > ----- Original Message -----
> > From: Jonathan Winterflood
> > To: Jan Mura
> > Cc: dev...@li...
> > Sent: Monday, May 07, 2007 9:08 AM
> > Subject: Re: [Dev-C++] Casting of int to string
> >
> >
> > Just a note:
> > """ It basically prints your integer into the character array, as long
as there is enough space to hold it """
> > Actually it will print the integer whether there is enough space or
not.. It is entirely Your job to make sure there is enough space, or else
sprintf will just keep on printing in memory after the end of the array.
Obviously this is a very bad idea, since there is other data there.
> > In this case, determining the necessary space is as easy as 'what's
the maximum digit count in an integer'... but in other cases, you can get
wierd crashes, wrong data for no apparent reason, or even create an exploit
in your program.
> >
> > Thought you might want to know that (and if you did, no offense
intended :)
> > Jonathan
> >
> >
> > On 5/7/07, Philip Bennefall < phi...@pb...> wrote:
> > This will do the job.
> > char outputstring[32];
> > sprintf(outputstring, "%d", integer);
> >
> > It basically prints your integer into the character array, as long
as there
> > is enough space to hold it. This method works both in C and C++.
There are
> > other methods such as stringstream, but they only work in C++. If
you're
> > compiling a C program, for this function to work you need to include
stdio.h
> > and for C++ it is cstdio.
> >
> > Regards
> > Philip Bennefall
> > ----- Original Message -----
> > From: "Jan Mura" <jan...@vo...>
> > To: <dev...@li... >
> > Sent: Monday, May 07, 2007 8:26 AM
> > Subject: [Dev-C++] Casting of int to string
> >
> >
> > > Hello,
> > >
> > > I would like to compare an integer with a string using strcmp().
So I need
> > > to cast the int type to string (*char). Is there some commone way
how to
> > > do
> > > it. Should I use & operator and adress of int in teh function? Or
> > > something
> > > else?
> > >
> > > Thank you very much
> > >
> > > Jan Mura
> > >
> > >
> >
> -------------------------------------------------------------------------
> > > This SF.net email is sponsored by DB2 Express
> > > Download DB2 Express C - the FREE version of DB2 express and take
> > > control of your XML. No limits. Just data. Click to get it now.
> > > http://sourceforge.net/powerbar/db2/
> > > _______________________________________________
> > > Dev-cpp-users mailing list
> > > Dev...@li...
> > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > >
> >
> >
>
-------------------------------------------------------------------------
> > This SF.net email is sponsored by DB2 Express
> > Download DB2 Express C - the FREE version of DB2 express and take
> > control of your XML. No limits. Just data. Click to get it now.
> > http://sourceforge.net/powerbar/db2/
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
> >
> >
> >
> > --
> > <Morpheus> linux, c'est une question de VI ou de MORE
> >
> >
>
> --------------------------------------------------------------------------
----
> >
> >
>
-------------------------------------------------------------------------
> > This SF.net email is sponsored by DB2 Express
> > Download DB2 Express C - the FREE version of DB2 express and take
> > control of your XML. No limits. Just data. Click to get it now.
> > http://sourceforge.net/powerbar/db2/
> >
> >
>
> --------------------------------------------------------------------------
----
> >
> >
> > _______________________________________________
> > Dev-cpp-users mailing list
> > Dev...@li...
> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> >
>
>
>
> __________ Informace od NOD32 2245 (20070506) __________
>
> Tato zprava byla proverena antivirovym systemem NOD32.
> http://www.nod32.cz
>
>
|
|
From: Jonathan W. <jon...@gm...> - 2007-05-07 10:33:02
|
Since the name is just a pointer, the malloc does not allocate _any_ memory
for the name, only 4 bytes(?) for the pointer.
You should seperately allocate the memory for the name, or use another
trick: allocte enough memory _after_ the structure to contain your name, in
the same malloc (this saves allocating lots of small blocks, in the case
that the name for that structure will not change)
eg:
member = malloc(sizeof(struct bet_list)+length_of_name_including_nul);
//allocate both
member->name = (char *)member + sizeof(struct bet_list); // point the name
at the memory after the structure
strcpy(member->name, name);
It might look slightly hacky, but it works fine :)
Any comments on this?
Obviously if you dno't know the size of the string before allocatingthe
struct, or it may change, you'll have to allocate them separately:
member = malloc(sizeof(struct bet_list)); //allocate just one
member->name=NULL; // for checking: malloc does not initialize data (I guess
you already know that)
member->next = NULL;
/* ... */
if (member->name) {
free(member->name); //in case you are changing names
member->name=NULL; // if you aren't going to put the name back immediately
}
member->name = malloc(strlen(name)+1); //allocate the name
strcpy(member->name, name);
Jonathan
On 5/7/07, Jan Mura <jan...@vo...> wrote:
>
>
> Thank you, it came to my mind what about the NULL character at the end of
> the string.
>
> Maybe one more thing. I am not sure if my code is ok because of the
> similar
> reasons about some illegal memory usage.
> So I have something like
>
> struct bet_list
> {
> int id;
> char *name;
> struct bet_list *next;
> };
> ...
> struct bet_list *member, *temp;
>
> member = malloc(sizeof(struct bet_list));
>
> member->id = 1;
> strcpy(member->name, "some string here");
> member->next = NULL;
>
> ...
>
> I am not sure if malloc allocates enough space if it dont know how long is
> a
> string I would like to put in.
>
> Thanks again
>
> Jan Mura
>
> ---- Original Message -----
> From: "Per Westermark" <pw...@ia...>
> To: "Philip Bennefall" <phi...@pb...>
> Cc: "Jonathan Winterflood" <jon...@gm...>; "Jan Mura"
> <jan...@vo...>; <dev...@li...>
> Sent: Monday, May 07, 2007 10:21 AM
> Subject: Re: [Dev-C++] Casting of int to string
>
>
> > Better C libraries have the snprintf() function, that takes the size of
> > the buffer as an input parameter.
> >
> > /pwm
> >
> > On Mon, 7 May 2007, Philip Bennefall wrote:
> >
> > > Sorry, I should've phrased it differently. Yup, allocating too little
> memory is a bad idea in any situation because the function has no way of
> knowing when it is supposed to stop writing. I just put 32 in there
> because
> it ensures (100 %) that the entire value will be stored including the Null
> terminator.
> > >
> > > Regards
> > > Philip Bennefall
> > > ----- Original Message -----
> > > From: Jonathan Winterflood
> > > To: Jan Mura
> > > Cc: dev...@li...
> > > Sent: Monday, May 07, 2007 9:08 AM
> > > Subject: Re: [Dev-C++] Casting of int to string
> > >
> > >
> > > Just a note:
> > > """ It basically prints your integer into the character array, as
> long
> as there is enough space to hold it """
> > > Actually it will print the integer whether there is enough space or
> not.. It is entirely Your job to make sure there is enough space, or else
> sprintf will just keep on printing in memory after the end of the array.
> Obviously this is a very bad idea, since there is other data there.
> > > In this case, determining the necessary space is as easy as 'what's
> the maximum digit count in an integer'... but in other cases, you can get
> wierd crashes, wrong data for no apparent reason, or even create an
> exploit
> in your program.
> > >
> > > Thought you might want to know that (and if you did, no offense
> intended :)
> > > Jonathan
> > >
> > >
> > > On 5/7/07, Philip Bennefall < phi...@pb...> wrote:
> > > This will do the job.
> > > char outputstring[32];
> > > sprintf(outputstring, "%d", integer);
> > >
> > > It basically prints your integer into the character array, as long
> as there
> > > is enough space to hold it. This method works both in C and C++.
> There are
> > > other methods such as stringstream, but they only work in C++. If
> you're
> > > compiling a C program, for this function to work you need to
> include
> stdio.h
> > > and for C++ it is cstdio.
> > >
> > > Regards
> > > Philip Bennefall
> > > ----- Original Message -----
> > > From: "Jan Mura" <jan...@vo...>
> > > To: <dev...@li... >
> > > Sent: Monday, May 07, 2007 8:26 AM
> > > Subject: [Dev-C++] Casting of int to string
> > >
> > >
> > > > Hello,
> > > >
> > > > I would like to compare an integer with a string using strcmp().
> So I need
> > > > to cast the int type to string (*char). Is there some commone
> way
> how to
> > > > do
> > > > it. Should I use & operator and adress of int in teh function?
> Or
> > > > something
> > > > else?
> > > >
> > > > Thank you very much
> > > >
> > > > Jan Mura
> > > >
> > > >
> > >
>
>
>
> >
> -------------------------------------------------------------------------
> > > > This SF.net email is sponsored by DB2 Express
> > > > Download DB2 Express C - the FREE version of DB2 express and
> take
> > > > control of your XML. No limits. Just data. Click to get it now.
> > > > http://sourceforge.net/powerbar/db2/
> > > > _______________________________________________
> > > > Dev-cpp-users mailing list
> > > > Dev...@li...
> > > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > >
> > >
> > >
> >
>
> -------------------------------------------------------------------------
> > > This SF.net email is sponsored by DB2 Express
> > > Download DB2 Express C - the FREE version of DB2 express and take
> > > control of your XML. No limits. Just data. Click to get it now.
> > > http://sourceforge.net/powerbar/db2/
> > > _______________________________________________
> > > Dev-cpp-users mailing list
> > > Dev...@li...
> > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > >
> > >
> > >
> > >
> > > --
> > > <Morpheus> linux, c'est une question de VI ou de MORE
> > >
> > >
> >
> >
> --------------------------------------------------------------------------
> ----
> > >
> > >
> >
>
> -------------------------------------------------------------------------
> > > This SF.net email is sponsored by DB2 Express
> > > Download DB2 Express C - the FREE version of DB2 express and take
> > > control of your XML. No limits. Just data. Click to get it now.
> > > http://sourceforge.net/powerbar/db2/
> > >
> > >
> >
> >
> --------------------------------------------------------------------------
> ----
> > >
> > >
> > > _______________________________________________
> > > Dev-cpp-users mailing list
> > > Dev...@li...
> > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > >
> >
> >
> >
> > __________ Informace od NOD32 2245 (20070506) __________
> >
> > Tato zprava byla proverena antivirovym systemem NOD32.
> > http://www.nod32.cz
> >
> >
>
>
--
<Morpheus> linux, c'est une question de VI ou de MORE
|
|
From: Jan M. <jan...@vo...> - 2007-05-07 10:56:09
|
Oh God, thank you. It is enough for today I think.
Jan Mura
----- Original Message -----
From: "Jonathan Winterflood" <jon...@gm...>
To: "Jan Mura" <jan...@vo...>
Cc: "Per Westermark" <pw...@ia...>; "Philip Bennefall"
<phi...@pb...>; <dev...@li...>
Sent: Monday, May 07, 2007 12:32 PM
Subject: Re: [Dev-C++] Casting of int to string
> Since the name is just a pointer, the malloc does not allocate _any_
memory
> for the name, only 4 bytes(?) for the pointer.
> You should seperately allocate the memory for the name, or use another
> trick: allocte enough memory _after_ the structure to contain your name,
in
> the same malloc (this saves allocating lots of small blocks, in the case
> that the name for that structure will not change)
> eg:
> member = malloc(sizeof(struct bet_list)+length_of_name_including_nul);
> //allocate both
> member->name = (char *)member + sizeof(struct bet_list); // point the
name
> at the memory after the structure
> strcpy(member->name, name);
>
> It might look slightly hacky, but it works fine :)
> Any comments on this?
>
> Obviously if you dno't know the size of the string before allocatingthe
> struct, or it may change, you'll have to allocate them separately:
>
> member = malloc(sizeof(struct bet_list)); //allocate just one
> member->name=NULL; // for checking: malloc does not initialize data (I
guess
> you already know that)
> member->next = NULL;
> /* ... */
> if (member->name) {
> free(member->name); //in case you are changing names
> member->name=NULL; // if you aren't going to put the name back
immediately
> }
> member->name = malloc(strlen(name)+1); //allocate the name
> strcpy(member->name, name);
>
> Jonathan
>
> On 5/7/07, Jan Mura <jan...@vo...> wrote:
> >
> >
> > Thank you, it came to my mind what about the NULL character at the end
of
> > the string.
> >
> > Maybe one more thing. I am not sure if my code is ok because of the
> > similar
> > reasons about some illegal memory usage.
> > So I have something like
> >
> > struct bet_list
> > {
> > int id;
> > char *name;
> > struct bet_list *next;
> > };
> > ...
> > struct bet_list *member, *temp;
> >
> > member = malloc(sizeof(struct bet_list));
> >
> > member->id = 1;
> > strcpy(member->name, "some string here");
> > member->next = NULL;
> >
> > ...
> >
> > I am not sure if malloc allocates enough space if it dont know how long
is
> > a
> > string I would like to put in.
> >
> > Thanks again
> >
> > Jan Mura
> >
> > ---- Original Message -----
> > From: "Per Westermark" <pw...@ia...>
> > To: "Philip Bennefall" <phi...@pb...>
> > Cc: "Jonathan Winterflood" <jon...@gm...>; "Jan Mura"
> > <jan...@vo...>; <dev...@li...>
> > Sent: Monday, May 07, 2007 10:21 AM
> > Subject: Re: [Dev-C++] Casting of int to string
> >
> >
> > > Better C libraries have the snprintf() function, that takes the size
of
> > > the buffer as an input parameter.
> > >
> > > /pwm
> > >
> > > On Mon, 7 May 2007, Philip Bennefall wrote:
> > >
> > > > Sorry, I should've phrased it differently. Yup, allocating too
little
> > memory is a bad idea in any situation because the function has no way of
> > knowing when it is supposed to stop writing. I just put 32 in there
> > because
> > it ensures (100 %) that the entire value will be stored including the
Null
> > terminator.
> > > >
> > > > Regards
> > > > Philip Bennefall
> > > > ----- Original Message -----
> > > > From: Jonathan Winterflood
> > > > To: Jan Mura
> > > > Cc: dev...@li...
> > > > Sent: Monday, May 07, 2007 9:08 AM
> > > > Subject: Re: [Dev-C++] Casting of int to string
> > > >
> > > >
> > > > Just a note:
> > > > """ It basically prints your integer into the character array, as
> > long
> > as there is enough space to hold it """
> > > > Actually it will print the integer whether there is enough space
or
> > not.. It is entirely Your job to make sure there is enough space, or
else
> > sprintf will just keep on printing in memory after the end of the array.
> > Obviously this is a very bad idea, since there is other data there.
> > > > In this case, determining the necessary space is as easy as
'what's
> > the maximum digit count in an integer'... but in other cases, you can
get
> > wierd crashes, wrong data for no apparent reason, or even create an
> > exploit
> > in your program.
> > > >
> > > > Thought you might want to know that (and if you did, no offense
> > intended :)
> > > > Jonathan
> > > >
> > > >
> > > > On 5/7/07, Philip Bennefall < phi...@pb...>
wrote:
> > > > This will do the job.
> > > > char outputstring[32];
> > > > sprintf(outputstring, "%d", integer);
> > > >
> > > > It basically prints your integer into the character array, as
long
> > as there
> > > > is enough space to hold it. This method works both in C and C++.
> > There are
> > > > other methods such as stringstream, but they only work in C++.
If
> > you're
> > > > compiling a C program, for this function to work you need to
> > include
> > stdio.h
> > > > and for C++ it is cstdio.
> > > >
> > > > Regards
> > > > Philip Bennefall
> > > > ----- Original Message -----
> > > > From: "Jan Mura" <jan...@vo...>
> > > > To: <dev...@li... >
> > > > Sent: Monday, May 07, 2007 8:26 AM
> > > > Subject: [Dev-C++] Casting of int to string
> > > >
> > > >
> > > > > Hello,
> > > > >
> > > > > I would like to compare an integer with a string using
strcmp().
> > So I need
> > > > > to cast the int type to string (*char). Is there some commone
> > way
> > how to
> > > > > do
> > > > > it. Should I use & operator and adress of int in teh
function?
> > Or
> > > > > something
> > > > > else?
> > > > >
> > > > > Thank you very much
> > > > >
> > > > > Jan Mura
> > > > >
> > > > >
> > > >
> >
> >
> >
> > >
>
> -------------------------------------------------------------------------
> > > > > This SF.net email is sponsored by DB2 Express
> > > > > Download DB2 Express C - the FREE version of DB2 express and
> > take
> > > > > control of your XML. No limits. Just data. Click to get it
now.
> > > > > http://sourceforge.net/powerbar/db2/
> > > > > _______________________________________________
> > > > > Dev-cpp-users mailing list
> > > > > Dev...@li...
> > > > > TO UNSUBSCRIBE:
http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > > >
> > > >
> > > >
> > >
> >
>
-------------------------------------------------------------------------
> > > > This SF.net email is sponsored by DB2 Express
> > > > Download DB2 Express C - the FREE version of DB2 express and
take
> > > > control of your XML. No limits. Just data. Click to get it now.
> > > > http://sourceforge.net/powerbar/db2/
> > > > _______________________________________________
> > > > Dev-cpp-users mailing list
> > > > Dev...@li...
> > > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > <Morpheus> linux, c'est une question de VI ou de MORE
> > > >
> > > >
> > >
> > >
>
> --------------------------------------------------------------------------
> > ----
> > > >
> > > >
> > >
> >
>
-------------------------------------------------------------------------
> > > > This SF.net email is sponsored by DB2 Express
> > > > Download DB2 Express C - the FREE version of DB2 express and take
> > > > control of your XML. No limits. Just data. Click to get it now.
> > > > http://sourceforge.net/powerbar/db2/
> > > >
> > > >
> > >
> > >
>
> --------------------------------------------------------------------------
> > ----
> > > >
> > > >
> > > > _______________________________________________
> > > > Dev-cpp-users mailing list
> > > > Dev...@li...
> > > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > >
> > >
> > >
> > >
> > > __________ Informace od NOD32 2245 (20070506) __________
> > >
> > > Tato zprava byla proverena antivirovym systemem NOD32.
> > > http://www.nod32.cz
> > >
> > >
> >
> >
>
>
> --
> <Morpheus> linux, c'est une question de VI ou de MORE
>
>
>
> __________ Informace od NOD32 2246 (20070507) __________
>
> Tato zprava byla proverena antivirovym systemem NOD32.
> http://www.nod32.cz
>
|
|
From: Per W. <pw...@ia...> - 2007-05-07 13:32:10
|
Note that strdup() can be used to both allocate memory for a string, and
copy the string data to the allocated buffer.
/pwm
On Mon, 7 May 2007, Jan Mura wrote:
> Oh God, thank you. It is enough for today I think.
>
> Jan Mura
> ----- Original Message -----
> From: "Jonathan Winterflood" <jon...@gm...>
> To: "Jan Mura" <jan...@vo...>
> Cc: "Per Westermark" <pw...@ia...>; "Philip Bennefall"
> <phi...@pb...>; <dev...@li...>
> Sent: Monday, May 07, 2007 12:32 PM
> Subject: Re: [Dev-C++] Casting of int to string
>
>
> > Since the name is just a pointer, the malloc does not allocate _any_
> memory
> > for the name, only 4 bytes(?) for the pointer.
> > You should seperately allocate the memory for the name, or use another
> > trick: allocte enough memory _after_ the structure to contain your name,
> in
> > the same malloc (this saves allocating lots of small blocks, in the case
> > that the name for that structure will not change)
> > eg:
> > member = malloc(sizeof(struct bet_list)+length_of_name_including_nul);
> > //allocate both
> > member->name = (char *)member + sizeof(struct bet_list); // point the
> name
> > at the memory after the structure
> > strcpy(member->name, name);
> >
> > It might look slightly hacky, but it works fine :)
> > Any comments on this?
> >
> > Obviously if you dno't know the size of the string before allocatingthe
> > struct, or it may change, you'll have to allocate them separately:
> >
> > member = malloc(sizeof(struct bet_list)); //allocate just one
> > member->name=NULL; // for checking: malloc does not initialize data (I
> guess
> > you already know that)
> > member->next = NULL;
> > /* ... */
> > if (member->name) {
> > free(member->name); //in case you are changing names
> > member->name=NULL; // if you aren't going to put the name back
> immediately
> > }
> > member->name = malloc(strlen(name)+1); //allocate the name
> > strcpy(member->name, name);
> >
> > Jonathan
> >
> > On 5/7/07, Jan Mura <jan...@vo...> wrote:
> > >
> > >
> > > Thank you, it came to my mind what about the NULL character at the end
> of
> > > the string.
> > >
> > > Maybe one more thing. I am not sure if my code is ok because of the
> > > similar
> > > reasons about some illegal memory usage.
> > > So I have something like
> > >
> > > struct bet_list
> > > {
> > > int id;
> > > char *name;
> > > struct bet_list *next;
> > > };
> > > ...
> > > struct bet_list *member, *temp;
> > >
> > > member = malloc(sizeof(struct bet_list));
> > >
> > > member->id = 1;
> > > strcpy(member->name, "some string here");
> > > member->next = NULL;
> > >
> > > ...
> > >
> > > I am not sure if malloc allocates enough space if it dont know how long
> is
> > > a
> > > string I would like to put in.
> > >
> > > Thanks again
> > >
> > > Jan Mura
> > >
> > > ---- Original Message -----
> > > From: "Per Westermark" <pw...@ia...>
> > > To: "Philip Bennefall" <phi...@pb...>
> > > Cc: "Jonathan Winterflood" <jon...@gm...>; "Jan Mura"
> > > <jan...@vo...>; <dev...@li...>
> > > Sent: Monday, May 07, 2007 10:21 AM
> > > Subject: Re: [Dev-C++] Casting of int to string
> > >
> > >
> > > > Better C libraries have the snprintf() function, that takes the size
> of
> > > > the buffer as an input parameter.
> > > >
> > > > /pwm
> > > >
> > > > On Mon, 7 May 2007, Philip Bennefall wrote:
> > > >
> > > > > Sorry, I should've phrased it differently. Yup, allocating too
> little
> > > memory is a bad idea in any situation because the function has no way of
> > > knowing when it is supposed to stop writing. I just put 32 in there
> > > because
> > > it ensures (100 %) that the entire value will be stored including the
> Null
> > > terminator.
> > > > >
> > > > > Regards
> > > > > Philip Bennefall
> > > > > ----- Original Message -----
> > > > > From: Jonathan Winterflood
> > > > > To: Jan Mura
> > > > > Cc: dev...@li...
> > > > > Sent: Monday, May 07, 2007 9:08 AM
> > > > > Subject: Re: [Dev-C++] Casting of int to string
> > > > >
> > > > >
> > > > > Just a note:
> > > > > """ It basically prints your integer into the character array, as
> > > long
> > > as there is enough space to hold it """
> > > > > Actually it will print the integer whether there is enough space
> or
> > > not.. It is entirely Your job to make sure there is enough space, or
> else
> > > sprintf will just keep on printing in memory after the end of the array.
> > > Obviously this is a very bad idea, since there is other data there.
> > > > > In this case, determining the necessary space is as easy as
> 'what's
> > > the maximum digit count in an integer'... but in other cases, you can
> get
> > > wierd crashes, wrong data for no apparent reason, or even create an
> > > exploit
> > > in your program.
> > > > >
> > > > > Thought you might want to know that (and if you did, no offense
> > > intended :)
> > > > > Jonathan
> > > > >
> > > > >
> > > > > On 5/7/07, Philip Bennefall < phi...@pb...>
> wrote:
> > > > > This will do the job.
> > > > > char outputstring[32];
> > > > > sprintf(outputstring, "%d", integer);
> > > > >
> > > > > It basically prints your integer into the character array, as
> long
> > > as there
> > > > > is enough space to hold it. This method works both in C and C++.
> > > There are
> > > > > other methods such as stringstream, but they only work in C++.
> If
> > > you're
> > > > > compiling a C program, for this function to work you need to
> > > include
> > > stdio.h
> > > > > and for C++ it is cstdio.
> > > > >
> > > > > Regards
> > > > > Philip Bennefall
> > > > > ----- Original Message -----
> > > > > From: "Jan Mura" <jan...@vo...>
> > > > > To: <dev...@li... >
> > > > > Sent: Monday, May 07, 2007 8:26 AM
> > > > > Subject: [Dev-C++] Casting of int to string
> > > > >
> > > > >
> > > > > > Hello,
> > > > > >
> > > > > > I would like to compare an integer with a string using
> strcmp().
> > > So I need
> > > > > > to cast the int type to string (*char). Is there some commone
> > > way
> > > how to
> > > > > > do
> > > > > > it. Should I use & operator and adress of int in teh
> function?
> > > Or
> > > > > > something
> > > > > > else?
> > > > > >
> > > > > > Thank you very much
> > > > > >
> > > > > > Jan Mura
> > > > > >
> > > > > >
> > > > >
> > >
> > >
> > >
> > > >
> >
> > -------------------------------------------------------------------------
> > > > > > This SF.net email is sponsored by DB2 Express
> > > > > > Download DB2 Express C - the FREE version of DB2 express and
> > > take
> > > > > > control of your XML. No limits. Just data. Click to get it
> now.
> > > > > > http://sourceforge.net/powerbar/db2/
> > > > > > _______________________________________________
> > > > > > Dev-cpp-users mailing list
> > > > > > Dev...@li...
> > > > > > TO UNSUBSCRIBE:
> http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > > > >
> > > > >
> > > > >
> > > >
> > >
> >
> -------------------------------------------------------------------------
> > > > > This SF.net email is sponsored by DB2 Express
> > > > > Download DB2 Express C - the FREE version of DB2 express and
> take
> > > > > control of your XML. No limits. Just data. Click to get it now.
> > > > > http://sourceforge.net/powerbar/db2/
> > > > > _______________________________________________
> > > > > Dev-cpp-users mailing list
> > > > > Dev...@li...
> > > > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > <Morpheus> linux, c'est une question de VI ou de MORE
> > > > >
> > > > >
> > > >
> > > >
> >
> > --------------------------------------------------------------------------
> > > ----
> > > > >
> > > > >
> > > >
> > >
> >
> -------------------------------------------------------------------------
> > > > > This SF.net email is sponsored by DB2 Express
> > > > > Download DB2 Express C - the FREE version of DB2 express and take
> > > > > control of your XML. No limits. Just data. Click to get it now.
> > > > > http://sourceforge.net/powerbar/db2/
> > > > >
> > > > >
> > > >
> > > >
> >
> > --------------------------------------------------------------------------
> > > ----
> > > > >
> > > > >
> > > > > _______________________________________________
> > > > > Dev-cpp-users mailing list
> > > > > Dev...@li...
> > > > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> > > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
> > > > >
> > > >
> > > >
> > > >
> > > > __________ Informace od NOD32 2245 (20070506) __________
> > > >
> > > > Tato zprava byla proverena antivirovym systemem NOD32.
> > > > http://www.nod32.cz
> > > >
> > > >
> > >
> > >
> >
> >
> > --
> > <Morpheus> linux, c'est une question de VI ou de MORE
> >
> >
> >
> > __________ Informace od NOD32 2246 (20070507) __________
> >
> > Tato zprava byla proverena antivirovym systemem NOD32.
> > http://www.nod32.cz
> >
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|
|
From: Mux0x55 <mu...@gm...> - 2007-05-07 10:36:56
|
Jonathan Winterflood ha scritto: > When you create the project you put the code in, you should select the > language to use (bottom-right of the dialog) > Also, in Project Options > Files, you can change the settings on a > file-by-file basis. > > Happy coding :) > > Jonathan > > On 5/7/07, *Mux0x55 otto a uno* <mu...@gm... > <mailto:mu...@gm...>> wrote: > > Good evening @ all, > I have a big problem. I want to use DevCpp to compile C progs > only, but I can't compile because it gives me this compilation > error: "redeclaration of built in type bool". How can I solve the > problem? Is there a method to disable c++ compiler ? Help me > please. I'm a student of IT Engineering and I'm using the Roberts > library of "Programming with abstractions in C" . I have to > use the devCpp and I have to use these libraries. Help me again. > Thank You. > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > <mailto:Dev...@li...> > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > <https://lists.sourceforge.net/lists/listinfo/dev-cpp-users> > > I do this , but It doesn't work... I have always this compile error... > -- > <Morpheus> linux, c'est une question de VI ou de MORE |