-
Junior Member
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);
}
-
Junior Member
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
-
Forum Rules