SIGSEGV error received while implementing string functions

  • From: "acsabir" < >
  • To:
  • Subject: SIGSEGV error received while implementing string functions
  • Date: Thu, 17 Jan 2013 15:45:43 -0500

Hi,

I was coding my implementation of some string functions. At some point, run 
failed and I went into debug mode. In the debug mode I received following 
error:


> Signal received: SIGSEGV (?) with sigcode ? (?)
> From process: ?
> For program socket_deneme, pid 4,169
> 
> You may discard the signal or forward it and you may continue or pause the 
> process
> To control which signals are caught or ignored use Debug->Dbx Configure


Here is the code of the function that fails:


Code:
char *to_upper(char *src)
{
    int len = strlen(src),
        i;
    
    for (i = 0; i < len; i++)
        if (*(src + i) >= 'a' && *(src + i) <= 'z')
            *(src + i) -= ('a' - 'A');
    
    return src;
}



Function resides in a header file.

It fails on line :


Code:
*(src + i) -= ('a' - 'A');



And here is the main :


Code:
#include "strings.h"


/*
 * 
 */
int main(void) {

    char *s1;
    
    s1 = "   ali ata bak.   ";
    
    printf("%d\n", strlen(s1));
    trim(s1);
    printf("%d\n", strlen(s1));
    
    return 0;
}



What am I doing wrong? And why do I get "?"s instead of a number?






SIGSEGV error received while implementing string functions

acsabir 01/17/2013

SIGSEGV error received while implementing string functions

soldatov 01/18/2013

Re: SIGSEGV error received while implementing string functions

paulf 01/18/2013

SIGSEGV error received while implementing string functions

acsabir 01/20/2013

Re: SIGSEGV error received while implementing string functions

Paul Floyd 01/20/2013

Project Features

About this Project

CND was started in November 2009, is owned by DimaZh, and has 130 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close