473,804 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why this crash?

Hi,
It could be a very simple problem, but i can not see it...

Here is the code:

char* lower(char* str){
char* p = str;
while ( *str ) {
*str = tolower(*str); <=====crash!
str++;
}
return p;
}

DO you see why?

Jul 3 '07 #1
16 1726
li*****@hotmail .com wrote:
Hi,
It could be a very simple problem, but i can not see it...

Here is the code:

char* lower(char* str){
char* p = str;
while ( *str ) {
*str = tolower(*str); <=====crash!
str++;
}
return p;
}
After removing the "<=====cras h!":

test.c: In function ‘lower’:
test.c:4: warning: implicit declaration of function ‘tolower’
/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/../../../../lib64/crt1.o: In function
`_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status

Please, when possible, post complete compilable programs.
DO you see why?
You have not posted enough code to make this clear. One likely possibility
is explained in the FAQ at <http://c-faq.com/decl/strlitinit.html >, but
there are other possibilities. If this is what happened, then the problem
is not in the code that you posted, but in how you call the lower function.
If you had posted a complete compilable program, it would have been
possible to be sure if this is what happened.
Jul 3 '07 #2
li*****@hotmail .com writes:
It could be a very simple problem, but i can not see it...

Here is the code:

char* lower(char* str){
char* p = str;
while ( *str ) {
*str = tolower(*str); <=====crash!
str++;
}
return p;
}

DO you see why?
No, because you didn't post the entire program, so we can't see where
the actual error is.

But I note that if you call your lower() function with a string
literal as the argument, a crash is very likely.

You should also be careful with the argument you pass to tolower(). A
negative value other than EOF causes undefined behavior; if plain char
is signed on your system, that could also cause a crash.

--
Keith Thompson (The_Other_Keit h) 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."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 3 '07 #3
sid
On Jul 3, 5:37 am, linq...@hotmail .com wrote:
Hi,
It could be a very simple problem, but i can not see it...

Here is the code:

char* lower(char* str){
char* p = str;
while ( *str ) {
*str = tolower(*str); <=====crash!
str++;
}
return p;

}

DO you see why?
I am not sure but I think the argument is supposed to be passed like
char *str and not char* str. If I am wrong kindly correct me and also
please tell me the difference between the two.
Thank you
Jul 3 '07 #4
sid wrote:
I am not sure but I think the argument is supposed to be passed like
char *str and not char* str. If I am wrong kindly correct me and also
please tell me the difference between the two.
a) You are wrong
b) There is no difference
Thank you

Jul 3 '07 #5
On Jul 2, 11:01 pm, sid <kingsiddha...@ gmail.comwrote:
On Jul 3, 5:37 am, linq...@hotmail .com wrote:
Hi,
It could be a very simple problem, but i can not see it...
Here is the code:
char* lower(char* str){
char* p = str;
while ( *str ) {
*str = tolower(*str); <=====crash!
str++;
}
return p;
}
DO you see why?

I am not sure but I think the argument is supposed to be passed like
char *str and not char* str.
You are incorrect.
If I am wrong kindly correct me and also
please tell me the difference between the two.
There is no difference in this context, it is a matter of style.

Robert Gamble

Jul 3 '07 #6
On Jul 2, 8:01 pm, sid <kingsiddha...@ gmail.comwrote:
On Jul 3, 5:37 am, linq...@hotmail .com wrote:


Hi,
It could be a very simple problem, but i can not see it...
Here is the code:
char* lower(char* str){
char* p = str;
while ( *str ) {
*str = tolower(*str); <=====crash!
str++;
}
return p;
}
DO you see why?

I am not sure but I think the argument is supposed to be passed like
char *str and not char* str. If I am wrong kindly correct me
Consider yourself kindly corrected.
and also
please tell me the difference between the two.
The characters '*' and ' ' are transposed - that's the only difference.

Jul 3 '07 #7
li*****@hotmail .com wrote:
Hi,
It could be a very simple problem, but i can not see it...

Here is the code:

char* lower(char* str){
char* p = str;
while ( *str ) {
*str = tolower(*str); <=====crash!
str++;
}
return p;
}

DO you see why?
No. You only showed us part of the code. Post a complete, minimal
program that demonstrates the problem.

I'll bet you passed it a string literal.

Brian
Jul 3 '07 #8

<li*****@hotmai l.comha scritto nel messaggio news:11******** **************@ o11g2000prd.goo glegroups.com.. .
Hi,
It could be a very simple problem, but i can not see it...

Here is the code:

char* lower(char* str){
char* p = str;
while ( *str ) {
*str = tolower(*str); <=====crash!
Are plain chars signed on your system?
Try *str = (char)tolower(( unsigned char)*str);
str++;
}
return p;
}

DO you see why?

Jul 3 '07 #9

"sid" <ki***********@ gmail.comha scritto nel messaggio news:11******** **************@ g37g2000prf.goo glegroups.com.. .
On Jul 3, 5:37 am, linq...@hotmail .com wrote:
>Hi,
It could be a very simple problem, but i can not see it...

Here is the code:

char* lower(char* str){
char* p = str;
while ( *str ) {
*str = tolower(*str); <=====crash!
str++;
}
return p;

}

DO you see why?

I am not sure but I think the argument is supposed to be passed like
char *str and not char* str. If I am wrong kindly correct me and also
please tell me the difference between the two.
None. You could also use char*str. Whitespace isn't significant in C.
Thank you


Jul 3 '07 #10

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

Similar topics

48
8518
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential problem. The program may crash unexpectedly while writing to the file. If so, my program should detect this during startup, and then (during startup) probably delete the data added to the file and redo the writing operation.
8
3217
by: Eric Brunel | last post by:
Hi all, I was creating a Tkinter widget in the style of the reversed tabs below Excel worksheets and I stepped in a serious problem: the code I made makes python crash with a seg fault, bus error or X11 BadGC error on both Solaris (2.6 and 2.7) and Linux (Mandrake 8.0); it doesn't crash on Windows. I tried to simplify the script, but I couldn't reproduce the crash with a simpler code. So the code below is somewhat long; sorry for that. ...
0
2275
by: roni | last post by:
hi. i have application written in vb.net + managed c++ dll that call also to unmanaged c++ function. the application crash. i open the dump file of the crash with WinDbg and that's is the call stack (using the sos.dll) : =====================================
10
9547
by: xixi | last post by:
i have db2 udb v8.1 on windows 64 bit 2003 server, after db2 server start , i found this in the db2diag.log, is this error? 2004-05-05-15.28.30.780000 Instance:DB2 Node:000 PID:1692(db2syscs.exe) TID:2860 Appid:AC10040A.GD5F.00FC56D8BEC5 base sys utilities sqledint Probe:30 Crash Recovery is needed. 2004-05-05-15.28.31.890000 Instance:DB2 Node:000
8
6465
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable .mdb. The query below query runs correctly and without error, but any attempt to save it causes Access to crash without a message, leaving the .ldb file. Opening the DB reveals it saved a blank "query1". I've upgraded to Jet SP 8, and I'm running...
14
5275
by: JK Peck | last post by:
I have a fairly large Access application that ran correctly in Access 2000. After upgrading to Access 2003 (and recompiling and updating references), it reliably crashes at a certain point. If I step through the VBA code, the crash does not occur. What is different about stepping through code instead of just running it? Any idea how to find the cause? I know about where it happens, but since it is Access itself crashing, finding a...
34
4479
by: NewToCPP | last post by:
Hi, Why does a C/C++ programs crash? When there is access to a null pointer or some thing like that programs crash, but why do they crash? Thanks.
12
5603
by: benjamin.krulewitch | last post by:
I'm debugging an issue with a C program that causes the computer to crash, and I'm attempting to log information immediately before the crash occurs. I us my BKprintLog function (see below) to write information into a log file. The problem is, i'm not confident that information i write to the log gets saved onto the hard drive before the crash occurs. My understanding of hard drives and OS are that because hard drives are so slow,...
110
10642
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst case scenario for MyISAM backend? Also is it possible to not to lose data but get them corrupted?
11
3056
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit (using .net version 3.5) is closed before the Ajax enable controls complete loading, then IE locks up. Does it in both IE7 and IE8. There is no issue when the controls are allowed to complete loading. Can you please tell me the best practice that handles this? Thanks.
0
9593
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7633
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.