Sponsored Content
Top Forums Programming Why segmentation(coredump) in the following code in C? Post 302530204 by AAKhan on Monday 13th of June 2011 08:44:58 AM
Old 06-13-2011
Why segmentation(coredump) in the following code in C?

hi
I have a method which returns char*. In this method am using switch case. I am getting segmentation error in case 49 and my code is
Code:
case 49:
          if(intFlag == 0210)
          {
                iiIDCode = atoi(getsubstring(sReq,262,2));
                l = atoi(getsubstring(sReq,26+2+iiIDCode,3));
                iiTemp = 26+2+iiFIDCode+l+3;
                j = atoi(getsubstring(sReq,iiTemp,3));
                k  = atoi(getsubstring(sReq,iiTemp+j+3,3));
                fprintf(fp,"\nCurrency Code Transaction:\t\t[%s]",getsubstring       (sReq,iiTemp+j+k+3+3,3));
                strcat(cRes,getsubstring(sReq,iiTemp+j+k+3+3,3));;
          }
         else if(intFlag == 110)
         {
          }   
break;

getsubstring is a method am using to substring the string and it is working fine. If i remove if and else part it is working fine but if i add if else condition in case 49: it is throwing error Segmentation Coredump. Why? What could be the error? How to solve this?
Thanks
 

9 More Discussions You Might Find Interesting

1. AIX

Segmentation fault(coredump)

Hi All Can anybody help me? When ever am trying to run topas system gives me an error Segmentation fault(coredump) does anybody ahve solution for this? (4 Replies)
Discussion started by: vjm
4 Replies

2. Solaris

lpstat gives segmentation coredump error

hi everyone, we have solaris 8 in sun v480 server. it gives this error. Segmentation Fault(coredump) can anyone help me in this - urgently. Regards Karthik C (8 Replies)
Discussion started by: cksriramchandra
8 Replies

3. UNIX for Advanced & Expert Users

Segmentation (CoreDump) error !!

Hi all, I am trying to create few directories using script and its giving me segmentation error. #!/bin/ksh createDirectories() createDirectories() { cat dirs | \ while read line do mkdir... (16 Replies)
Discussion started by: varungupta
16 Replies

4. Shell Programming and Scripting

Segmentation Fault(coredump)

I'm getting this error when trying to run a Acucobol program thru UNIX.. Segmentation Fault(coredump) Precompiler error prevents compilation of xxxxxx.co. Please help me in this case.. (1 Reply)
Discussion started by: Manish4
1 Replies

5. AIX

Segmentation fault in nsgetcinfo in aix 64-bit c code

Hello, I am running on a AIX5.2 server with Oracle 10g and 9i. My code compiles and works fine in 32-bit mode. The same code compiles in 64-bit and runs good. The program catches CNTRL-C signal to terminate. Only on 64-bit code when i hit CNTRL-C, the program exits with segmentation... (0 Replies)
Discussion started by: sumesh0710
0 Replies

6. Programming

C code : Segmentation fault

Hi Friends, I have written a small code in C which performs the below operations Task : 1 ) read line by line from a file. 2 ) assuming 3th and 4th fields of the file as GN and GNTO 3 ) The target file should contain all the fields except GNTO. 4... (3 Replies)
Discussion started by: kiran_bhatter
3 Replies

7. Programming

this code for addind polynomials using linked lists showed segmentation error..any help pls..

the error occurs in the function() "add" used... #include<stdio.h> #include<malloc.h> struct node { int exp; int coef; struct node * link; }; struct node * create_list(struct node *,int,int); void display(struct node *); struct node * add(struct node *,struct node *); ... (3 Replies)
Discussion started by: mscoder
3 Replies

8. Programming

This code keeps giving me a segmentation fault why?

#include<stdlib.h> #include <pthread.h> #include "tlpi_hdr.h" #include <stdio.h> static volatile int glob = 0; static struct { pthread_t t1,t2; } *thread; static void * /* Loop 'arg' times incrementing 'glob' */ threadFunc(void *arg) { int loops = *((int *) arg); ... (1 Reply)
Discussion started by: fwrlfo
1 Replies

9. Programming

Why does this example C code run and yet SHOULD either not compile or give a segmentation fault?

Apologies for any typos... Well guys, been researching 'goto' in C and they say that you can't 'goto' labels in another function as a segmentation fault will occur. However I have found a way to 'goto' a label in another function that is NOT main() using the asm() function. As you know I... (14 Replies)
Discussion started by: wisecracker
14 Replies
ATOI(3) 						     Linux Programmer's Manual							   ATOI(3)

NAME
atoi, atol, atoll - convert a string to an integer SYNOPSIS
#include <stdlib.h> int atoi(const char *nptr); long atol(const char *nptr); long long atoll(const char *nptr); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): atoll(): __ISOC99_SOURCE || || /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE DESCRIPTION
The atoi() function converts the initial portion of the string pointed to by nptr to int. The behavior is the same as strtol(nptr, NULL, 10); except that atoi() does not detect errors. The atol() and atoll() functions behave the same as atoi(), except that they convert the initial portion of the string to their return type of long or long long. RETURN VALUE
The converted value. ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7). +------------------------+---------------+----------------+ |Interface | Attribute | Value | +------------------------+---------------+----------------+ |atoi(), atol(), atoll() | Thread safety | MT-Safe locale | +------------------------+---------------+----------------+ CONFORMING TO
POSIX.1-2001, POSIX.1-2008, C99, SVr4, 4.3BSD. C89 and POSIX.1-1996 include the functions atoi() and atol() only. NOTES
Linux libc provided atoq() as an obsolete name for atoll(); atoq() is not provided by glibc. SEE ALSO
atof(3), strtod(3), strtol(3), strtoul(3) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. GNU
2016-03-15 ATOI(3)
All times are GMT -4. The time now is 08:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy