Solved

Signal 11 error

Posted on 2008-06-20
5
2,049 Views
Last Modified: 2008-06-23
I am getting a signal 11 error for strcpy function in Linux.
#include <stdio.h>
 

#define KEY_LEN                30

#define NO         0
 

int main()

{

char num[KEY_LEN+1];
 

printf("\nbefore strcpy");

strcpy(num , NO );

printf("\nafter strcpy %d",NO);

printf("\nafter strcpy %s",num);

}

Open in new window

0
Comment
Question by:bokaria
  • 3
  • 2
5 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 21830679
You cannot copy an integer value into a string.

Did you mean to use :

        sprintf(num, "%d", NO);
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21830682
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 50 total points
ID: 21830690
>strcpy(num , NO );
Is effectively
strcpy(num , NULL );

You are trying to read memory location 0 which in not readable ... hence you get a SIGSEGV or signal 11 or segmentation fault.
http://linux.die.net/man/7/signal

To copy number 0, use

#include <stdio.h>

 

#define KEY_LEN                30

#define NO         "0" 

//Not the quotes "0"

 

int main()

{

char num[KEY_LEN+1];

 

printf("\nbefore strcpy");

strcpy(num , NO );

printf("\nafter strcpy %s",NO); // we use %s to print the string "0"

printf("\nafter strcpy %s",num);

}

Open in new window

0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 21830710
>To copy number 0, use
Is probably not how intended it to sound ... I meant
To copy string "0" ... i.e. string consisting of a single char - 0
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21852764
Didn't you want to use an integer value, bokaria ? If so, take a look at what I posted.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now