- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: program dumping core file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2002 01:50 PM
04-08-2002 01:50 PM
program dumping core file
I have small program
******Working fine******************
main()
{
char *src="One";
char *dest="Two";
while ( src== NULL )
*dest++=*src++;
}
**********************************
******Dumping core******************
main()
{
char *src="One";
char *dest="Two";
while ( src )
*dest++=*src++;
}
**********************************
Anybody know diff.
Thanx
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2002 01:58 PM
04-08-2002 01:58 PM
Re: program dumping core file
Even your working versions is NOT working; it's simply doing nothing.
src is never NULL so the loop never executes.
main()
{
char *src="One";
char *dest="Two";
while ( src== NULL )
*dest++=*src++;
}
**********************************
******Dumping core******************
In this case, src is NEVER NULL, so it executes forever (or until a memory boundary is voilated and you dump core).
main()
{
char *src="One";
char *dest="Two";
while ( src )
*dest++=*src++;
}
You probably want something like this:
char *src="One",dest[80];
char *dptr = dest;
while (*src != '\0')
{
*dptr = *src;
++dptr;
++src;
}
*dptr = '\0';
This is not yet fully robust but it does indicate your problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2002 02:00 PM
04-08-2002 02:00 PM
Re: program dumping core file
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2002 02:32 PM
04-08-2002 02:32 PM
Re: program dumping core file
It is also better to use a ending space for these things, like an array of 20 characters. This way, you will never have these anoying memorydumps, because it cannot take all memory; only up until the end of the array.
Memory-errors like this, consuming all memory will not only corrupt your memoryspace, but can have some effects on other programs as well, using the same available space...
So take care about your memorymanagement. Read some manuals about 'malloc' as well.
Regards,
Ceesjan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2002 02:44 PM
04-08-2002 02:44 PM
Re: program dumping core file
Thanx for the inputs.
My problems resolved after putting
while ( *src != NULL )
I wanted to know why this is not working
*src="One" /*Last character is NULL char*/
while ( src != NULL )
*dest++=*src++; /* Moves to last NULL char after third iteration So "src" should be == NULL */
The following cases works
1> while ( *src != NULL )
*dest++=*src++;
2> *src=NULL;
*dest="Two";
while ( src != NULL )
*dest++=*src++;
3> *src=NULL;
*dest="Two";
while ( *src != NULL )
*dest++=*src++;
4> *src='\0';
*dest="Two";
while ( src != NULL )
*dest++=*src++;
5> *src='\0';
*dest="Two";
while ( *src != NULL )
*dest++=*src++;
Just curious...
Thanx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2002 07:26 PM
04-08-2002 07:26 PM
Re: program dumping core file
You have declared "src" to be a char pointer, and so it will hold a memory address. You can verify this by printing out src like so:
printf("src=%ld\n", src);
So (src== NULL) will never be true. Instead, you have to check the value of *src, (the contents of the memory address src points to) as you have discovered.
Hope this clarifies the matter.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 01:55 AM
04-09-2002 01:55 AM
Re: program dumping core file
N/A for me please
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2002 05:21 AM
04-09-2002 05:21 AM
Re: program dumping core file
This is what happening...
1> *src=NULL -> No memory is allocated/reserved by compiler for NULL character so address of
src is always 0.
So ( src== NULL ) becames true, It is
equivalent to
( 0 == 0 )
2> *src="One" -> Here 4th character is NULL and it is inserted by compiler. It has physical address.
content A B C \0
Address 100 101 102 103
So ( src== NULL ) Never becomes true, It is
equivalent to
( 103 == 0 )
Thanx