Memory Fault,Core dumped

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
nagoosk
Participant
Posts: 3
Joined: Wed Apr 23, 2008 3:54 am
Location: Chennai

Memory Fault,Core dumped

Post by nagoosk »

I have written a code in UNIX which is complied by using g++. Compling with turbo C didnt yield any errors, but with g++ I am getting Memory fault, core dumped. Could anyone help me out with this?

Given below is the code:

#include<stdio.h>

#include<string.h>
#include<stdlib.h>
#include<ctype.h>
main()
{
long int lt;
int i,r=0,p,m=0,q=0;
char a[100];
char *str;
//a=(char*) malloc(sizeof(char) *100);
str=(char *) malloc(sizeof(char) *100);


scanf("%s",str);
p=strlen(str);
for(i=0;i<p;i++)
{
if(isdigit(str)==0)
{
if((str!='.')&& str!='-')
{
m=1;
}
}
}
for(i=0;i<=p;i++)
{
if(str=='-')
r=r+1;
}
for(i=0;i<=p;i++)
{
if(str=='.')
q=q+1;
}
lt=atol(str);
if(p>=16 || strcmp(str,NULL)==0 || m==1 || r>1 ||q>1 || lt==0)
{
printf("ERROR");
}
else
{
//ltoa(lt,a,10);
sprintf(a,"%l",lt);
printf("%s",a);
}
}
Thanks
Buddi
DSRajesh
Premium Member
Premium Member
Posts: 297
Joined: Mon Feb 05, 2007 10:37 pm

Post by DSRajesh »

This is the issue you got with your malloc function what you are using in your program
RD
Post Reply