473,394 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Program Crash

My Program is crashing at
strupr(e2.n);


int main()
{
struct emp
{
char *n;
int age;
};

struct emp e1={"Dravid",50};
struct emp e2;
e2=e1;
strupr(e2.n);
printf("\ne1.n=%s\n",e1.n);
return 0;
}

Nov 15 '05 #1
5 1968
"Kuku" <me******@yahoo.com> writes:
My Program is crashing at
strupr(e2.n);


Your question is off topic in comp.lang.c.
The Standard C language does not define what a crashing program is.

--
Chris.
Nov 15 '05 #2
Le mercredi 3 août 2005 à 11:30, Kuku a écrit dans comp.lang.c*:
My Program is crashing at
strupr(e2.n);
I guess you want ask us why?
int main()
{
struct emp
{
char *n;
int age;
};

struct emp e1={"Dravid",50};
The constant litteral "Dravid" is stored somewhere in a place of memory
you're not supposed to modify, and e1.n now points to that memory.
struct emp e2;
e2=e1;
Now e2.n points to the same memory as e1.n
strupr(e2.n);


Here, you try to write in that memory. Since you're not supposed to
modify it, anything can happen. That is undefined behavior.

--
___________ 03/08/2005 12:09:13
_/ _ \_`_`_`_) Serge PACCALIN -- sp ad mailclub.net
\ \_L_) Il faut donc que les hommes commencent
-'(__) par n'être pas fanatiques pour mériter
_/___(_) la tolérance. -- Voltaire, 1763
Nov 15 '05 #3
Chris McDonald wrote:

Your question is off topic in comp.lang.c.
The Standard C language does not define what a crashing program is.


Don't be an idiot.


Brian
Nov 15 '05 #4
Kuku wrote on 03/08/05 :
My Program is crashing at
strupr(e2.n);

int main()
{
struct emp
{
char *n;
int age;
};

struct emp e1={"Dravid",50};
struct emp e2;
e2=e1;
strupr(e2.n);
printf("\ne1.n=%s\n",e1.n);
return 0;
}


A string literal is not mutable. The copy of structures creates a new
pointer to the same not mutable string.

You want an array of char.

#include <string.h>
#include <stdio.h>

struct emp
{
char n[32];
int age;
};

int main ()
{

struct emp e1 =
{
.n = "David",
.age = 50,
};
struct emp e2 = e1;

strupr (e2.n);

printf ("e1.n=%s\n", e1.n);
printf ("e2.n=%s\n", e2.n);

return 0;
}

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

I once asked an expert COBOL programmer, how to
declare local variables in COBOL, the reply was:
"what is a local variable?"
Nov 15 '05 #5
Serge Paccalin <sp@mailclub.no.spam.net.invalid> writes:
Le mercredi 3 août 2005 à 11:30, Kuku a écrit dans comp.lang.c*:

[...]
strupr(e2.n);


Here, you try to write in that memory. Since you're not supposed to
modify it, anything can happen. That is undefined behavior.


Assuming that strupr modifies the string to which e2.n points. That
seems likely, but there is no strupr() function in the standard.

Also, the original program is missing a #include directive for
<stdio.h> (it calls printf) and for whatever header declares strupr().

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Daragoth | last post by:
Hi, I'm writing a program using Metrowerks CodeWarrior 4.0 that determines the best possible combination of a data set by checking every possible combination. I found there were about 250,000,000...
6
by: Ken | last post by:
When running a program in the debugger, what would cause it to crash without any error messages? I get "The program has exited with code 0 (0x0)". The program is a MDI app with threading for...
17
by: UJ | last post by:
Is there any way for a windows service to start a windows program ? I have a service that will need to restart a windows app if it needs to. TIA - Jeff.
6
by: popone | last post by:
Hi All, I've developed a program that seems to crash randomly, from what I can tell it's after some user action. If it just sat there, it wouldn't crash. It's not an exception either, it's the...
4
by: eskimo | last post by:
Hello I have a situation, my program has a crash (SIGSEGV) for a reason that I don't know yet. I tried to analyze it using Valgrind but when I invoke the program with Valgrind, the crash no longer...
4
by: mike3 | last post by:
Hi. I seem to have made some progress on finding that bug in my program. I deactivated everything in the bignum package that was used except for the returning of BigFloat objects. I even...
4
by: Freddy Coal | last post by:
Hi, I would like know if something libraries or programs exist, and send error with a description if the program don't find the libraries, how can make that?. For example: In the use of...
13
by: Thomas Neubauer | last post by:
Hello, i am learning c# and have created now a simple project that just creates 6 random numbers. My form includes a button and 6 labels for the random numbers. The program seems to work...
2
by: jaddle | last post by:
I program I'm writing crashes when it exits with a segfault. I'm runnning under linux. Using gdb, i see that the crash happens after the last line of main(), which is just a return(EXIT_SUCCESS); If...
11
by: jmnat | last post by:
Hello, Let’s assume the following piece of code : This code works fine, its output is : "Exception : Could not execute f9". Nevertheless, in the catch clause, the pointer c is...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.