Results 1 to 2 of 2

Thread: Runtime error segmentation fault

  1. #1
    Junior Member
    Join Date
    Dec 2006
    Answers
    12

    Runtime error segmentation fault

    I have run the following program on both Turbo C compiler under Windows and cc compiler under Linux.It is perfectly OK In Turbo C where as it shows a runtime error segmentation fault in cc.
    Please help me.

    #include
    #include
    main()
    {
    char *s="Akshaya";
    char *t,ch;
    int l=0,i,c=0;
    t=(char *)malloc(strlen(s));
    t=s+len-1;
    for(i=0;i<=l/2;i++)
    {
    ch=*s;
    *s=*t;
    *t=ch;
    s++;
    t--;
    c++;
    }
    s=s-c;
    printf("%s",s);
    }


  2. #2
    Junior Member
    Join Date
    Nov 2007
    Answers
    9

    Thumbs up Re: Runtime error segmentation fault

    Hi!

    If you will use malloc() at your program in linux environment then you should add the slab.h as well as included files in slab.h.
    http://www.koders.com/c/fid3369125EB....aspx?s=slab.h
    The above link is very useful to compile your program.
    If any header file is required then take from this link and add it in your folder.

    If you are adding above header file in your folder then just include as like this in your pgm #include"slab.h"
    If already header file is there in your linux system as like this linux/slab.h are any other link then you put it in your pgm as #include<(links)/slab.h> eg: #include<linux/slab.h>
    #include<stdio.h>
    #include<string.h>
    #include<linux\slab.h>
    int main()
    {
    char *s="Akshaya";
    char *t,ch;
    int l=0,i,c=0,len=0;
    t=(char *)malloc(strlen(s));
    t=s+len-1;
    for(i=0;i<=l/2;i++)
    {
    ch=*s;
    *s=*t;
    *t=ch;
    s++;
    t--;
    c++;
    }
    s=s-c;
    printf("%s",s);
    }


    Regards
    venkat.G


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact