Objective C Bus Error 10
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more
Bus Error 10 Gulp
about Stack Overflow the company Business Learn more about hiring developers or posting node bus error 10 ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack
Webpack Bus Error
Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Bus error: 10 error up vote 23 down vote favorite 10 bus error c++ Here is my code #import #import int main(int argc, const char *argv[]) { char *str = "First string"; char *str2 = "Second string"; strcpy(str, str2); return 0; } It compiles just fine without any warning or errors, but when I run the app I get that error Bus error: 10 What I miss ? c share|improve this question asked Jan 3 '12 at 18:09 summerc 5312715 1 bus error linux Well, strlen(str)here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn
How To Debug Bus Error
more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users bus error (core dumped) Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping
Bus Error Vs Segmentation Fault
each other. Join them; it only takes a minute: Sign up bus error 10 in a c program [duplicate] up vote 2 down vote favorite 1 Possible Duplicate: What is the difference between char s[] and char *s http://stackoverflow.com/questions/8716714/bus-error-10-error in C? Why does this program give segmentation fault? here is the code: #include #include #include void reverse(char *c){ int len = strlen(c); char tmp; int i; for(i = 0; i < len; i++){ tmp = c[len-1-i]; c[len-1-i] = c[i]; c[i] = tmp; } } int main(){ char *s = "antonio"; //printf("%zd\n", strlen(s)); reverse(s); printf("%s\n", s); return 0; } The issue is in reverse(char *c), it take a string ad reverse it, but http://stackoverflow.com/questions/13442104/bus-error-10-in-a-c-program I don't understand where it goes wrong. c string share|improve this question asked Nov 18 '12 at 16:37 AR89 75221227 marked as duplicate by Mat, NullPoiиteя, codaddict, Paul R, Pascal Cuoq Nov 18 '12 at 17:36 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. 2 You're trying to modify a string literal. That's undefined behaviour and usually crashes. –Daniel Fischer Nov 18 '12 at 16:39 2 You've failed to use your compiler warnings and/or pay attention to them. Compile the code again with all warnings enabled and make sure you understand everything the compiler tells you. Automated tools can get you a very long way before you need to come to SO for help! –Kerrek SB Nov 18 '12 at 16:39 @KerrekSB I didn't receive any warning, I will see how to enable all the warnings of my compiler. –AR89 Nov 18 '12 at 17:14 add a comment| 1 Answer 1 active oldest votes up vote 3 down vote accepted There are two bugs here: 1) You are trying to change a string literal, which leads to undefined behavior, manifested as bus error in your case. Change char *s = "antonio"; to char s[] = "antonio"; 2) Also you are running your loop counter for entire st
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn http://stackoverflow.com/questions/7458854/bus-error-troubleshooting more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Bus error troubleshooting up vote 7 down vote favorite 3 I am trying reverse a string. This is the code I tried: #include #include int main(){ char bus error *c="I am a good boy"; printf("\n The input string is : %s\n",c); printf("\n The length of the string is : %d\n",strlen(c)); int i,j; char temp; int len=strlen(c); for(i=0,j=len-1;i<=j;i++,j--) { temp=c[i]; c[i]=c[j]; c[j]=temp; //printf("%c\t%c\n",*(c+i),*(c+(len-i-1))); } printf("\n reversed string is : %s\n\n",c); } The code outputs a Bus error : 10. But if I rewrite the same code as: int main(void) { char *str; str="I am a good boy"; int i,j; char temp; int len=strlen(str); char *ptr=NULL; ptr=malloc(sizeof(char)*(len)); bus error 10 ptr=strcpy(ptr,str); for (i=0, j=len-1; i<=j; i++, j--) { temp=ptr[i]; ptr[i]=ptr[j]; ptr[j]=temp; } printf("The reverse of the string is : %s\n",ptr); } It works perfectly fine. Why is the first code throwing bus error or segmentation fault? c string string-literals share|improve this question edited Sep 18 '11 at 1:11 Jeff Mercado 68.5k12128164 asked Sep 18 '11 at 1:03 sethu 60631227 1 please reformat your code. –Daniel A. White Sep 18 '11 at 1:04 I tried formatting as much as possible, but i really dont know how to have them aligned. –sethu Sep 18 '11 at 1:07 1 Please format your code by indenting it all with four spaces. –SLaks Sep 18 '11 at 1:08 1 In the future, highlight all your code, then click the {} icon. –Matthew Flaschen Sep 18 '11 at 1:14 1 @sethu: Be sure to look at the source of the question as it is now to see how you should format your code for the site. All it takes is pasting your code in, selecting it and pressing Ctrl + K to indent it all with 4 spaces. That alone should be sufficient. –Jeff Mercado Sep 18 '11 at 1:14 | show 1 more comment 5 Answers 5 active oldest votes up vote 15 down vote accepted The bus error occurs because in many (if not most or