kellan4459
IS-IT--Management
I am trying to take in input no matter the number of spaces so that I get two numbers. If there are more than two numbers on the line I want to print error and exit program. The steps I was trying to take is to create a multidimensional pointer with pointers. However, I am not doing something right with the dynamic allocation
basically what I am looking to get is something that will take in each line
say
22 44
13 6
and put it into the pointers as the same input(similar to multidimensional array)
but if it is
22 44 6
print error and exit
I have the following code but getting several different errors
int **getin(void){
int scanfcheck, **holder, i=0;
char *buffer;
buffer = malloc(80);
holder=NULL;
if (buffer != NULL){
while(((scanfcheck=scanf("%s",buffer))!= EOF)){
int *temp=realloc(holder,(sizeof(holder)+sizeof(int)));
printf("holder size = %d\n",sizeof(holder));
printf("buffer = %s\n",buffer);
if(temp != NULL){
holder = temp;
holder=malloc(sizeof(buffer));
printf("sizeof holderI %d\n",sizeof(holder));
printf("inside if temp\n"
if (holder != NULL){
holder=(int*)buffer;
}
i++;
}
else
{
fprintf(stdout,"ERROR IN REALLOC"
break;
}
}}
else
{
fprintf(stdout,"ERROR IN MALLOC"
}
printf("i = %d\n",i);
while(i > 0){
printf("%s\n",(char *)holder);
i--;
}
return holder;
}
basically what I am looking to get is something that will take in each line
say
22 44
13 6
and put it into the pointers as the same input(similar to multidimensional array)
but if it is
22 44 6
print error and exit
I have the following code but getting several different errors
int **getin(void){
int scanfcheck, **holder, i=0;
char *buffer;
buffer = malloc(80);
holder=NULL;
if (buffer != NULL){
while(((scanfcheck=scanf("%s",buffer))!= EOF)){
int *temp=realloc(holder,(sizeof(holder)+sizeof(int)));
printf("holder size = %d\n",sizeof(holder));
printf("buffer = %s\n",buffer);
if(temp != NULL){
holder = temp;
holder=malloc(sizeof(buffer));
printf("sizeof holderI %d\n",sizeof(holder));
printf("inside if temp\n"
if (holder != NULL){
holder=(int*)buffer;
}
i++;
}
else
{
fprintf(stdout,"ERROR IN REALLOC"
break;
}
}}
else
{
fprintf(stdout,"ERROR IN MALLOC"
}
printf("i = %d\n",i);
while(i > 0){
printf("%s\n",(char *)holder);
i--;
}
return holder;
}