Home > Back-end >  For a dynamic memory allocation problem
For a dynamic memory allocation problem

Time:09-17

Session when working out problems, bosses help solve
Why to array the statements and p distribution dynamic space compile-time error reality, thanks to guide


# include "stdio.h"
# include "stdlib. H"
# include "string. H"
Void main ()
{
Int I, j, n.
Float * p;
Float * array;
If (=array (float *) calloc (9999, sizeof (float)) & amp; & P=(float *) malloc (sizeof (float)));
The else printf (" fail!" );
Gets (array);
N=strlen (array)
for(i=0; iFor (j=n - I - 1; J> 0; J -)
{
If (array [j] & gt; Array [1])
{
* p=array [j];
Array [j]=array [j - 1);
Array [] j - 1=* p;
}
}
for(i=0; iPrintf (" % 2 f ", array [I]);
Free (array);
free(p);
}

CodePudding user response:

Array=(float *) calloc (9999, sizeof (float).
P=(float *) malloc (sizeof (float).
If (array==NULL | | p==NULL) {printf (" fail ")};
The else...
Or the if (array!=NULL& & p!=NULL)
.
Else print f...
Also, this is you want the content under the implementation? If judgment over there would be no operation directly else? Also didn't {}, finish it apart from judgment rules is not standard, to tell the truth you the ifelse has no effect on the following code, no matter how are you this result will perform
 
Float * p=NULL;
Float * array=NULL;//pointer value assigned a NULL, otherwise is wild pointer
Array=(float *) calloc (9999, sizeof (float).
P=(float *) malloc (sizeof (float).
If (array==NULL | | p==NULL) {
Printf (" fail ");
}
The else {
Gets (array);
N=strlen (array);//don't; ?
for(i=0; iFor (j=n - I - 1; J> 0; J -)
{
If (array [j] & gt; Array [1])
{
* p=array [j];
Array [j]=array [j - 1);
Array [] j - 1=* p;
}
}
}
for(i=0; iPrintf (" % 2 f ", array [I]);
}
Free (array);
free(p);

Don't omit {} is not good at now, even if only one can save the time to use, or you've picked all don't know where to find, not scan function, you need to do about should be, release the premise is you want to have

CodePudding user response:

 if (=array (float *) calloc (9999, sizeof (float)) & amp; & P=(float *) malloc (sizeof (float))); 
The else printf (" fail!" );

This sentence has a problem, directly behind the IF a semicolon; , very strange,

CodePudding user response:

 # include "stdio.h" 
# include "stdlib. H"
# include "string. H"

//void main ()
Int main ()
{
Int I, j, n.
Float * p;
Float * array;

/*
If (=array (float *) calloc (9999, sizeof (float)) & amp; & P=(float *) malloc (sizeof (float)))
;
The else
Printf (" fail!" );//fail over? Behind the use of array and that's not the same p is there a problem?
*/
Array=(float *) calloc (999, sizeof (float).
if (! Array)
return -1;
P=(float *) malloc (sizeof (float).
if (! P)
return -1;

Gets (array);//use of float cache gets the wrong door I feel? The program also can perform?
N=strlen (array)
for(i=0; iFor (j=n - I - 1; J> 0; J -)
{
If (array [j] & gt; Array [1])
{
* p=array [j];
Array [j]=array [j - 1);
Array [] j - 1=* p;
}
}
for(i=0; iPrintf (" % 2 f ", array [I]);
Free (array);
free(p);
}


What is basic questions first to understand, gets on function, is to float type?

CodePudding user response:

reference 1st floor qq_1457346882 response:
array=(float *) calloc (9999, sizeof (float).
P=(float *) malloc (sizeof (float).
If (array==NULL | | p==NULL) {printf (" fail ")};
The else...
Or the if (array!=NULL& & p!=NULL)
.
Else print f...
Also, this is you want the content under the implementation? If judgment over there would be no operation directly else? Also didn't {}, finish it apart from judgment rules is not standard, to tell the truth you the ifelse has no effect on the following code, no matter how are you this result will perform
 
Float * p=NULL;
Float * array=NULL;//pointer value assigned a NULL, otherwise is wild pointer
Array=(float *) calloc (9999, sizeof (float).
P=(float *) malloc (sizeof (float).
If (array==NULL | | p==NULL) {
Printf (" fail ");
}
The else {
Gets (array);
N=strlen (array);//don't; ?
for(i=0; iFor (j=n - I - 1; J> 0; J -)
{
If (array [j] & gt; Array [1])
{
* p=array [j];
Array [j]=array [j - 1);
Array [] j - 1=* p;
}
}
}
for(i=0; iPrintf (" % 2 f ", array [I]);
}
Free (array);
free(p);

Don't omit {} is not good at now, even if only one can save the time to use, or you've picked all don't know where to find, not scan function, you need to do about should be, release the premise is you must have

Gets a float buffer can be?

CodePudding user response:

references 4 building self-confidence boy reply:
Quote: refer to 1st floor qq_1457346882 response:

Array=(float *) calloc (9999, sizeof (float).
P=(float *) malloc (sizeof (float).
If (array==NULL | | p==NULL) {printf (" fail ")};
The else...
Or the if (array!=NULL& & p!=NULL)
.
Else print f...
Also, this is you want the content under the implementation? If judgment over there would be no operation directly else? Also didn't {}, finish it apart from judgment rules is not standard, to tell the truth you the ifelse has no effect on the following code, no matter how are you this result will perform
 
Float * p=NULL;
Float * array=NULL;//pointer value assigned a NULL, otherwise is wild pointer
Array=(float *) calloc (9999, sizeof (float).
P=(float *) malloc (sizeof (float).
If (array==NULL | | p==NULL) {
Printf (" fail ");
}
The else {
Gets (array);
N=strlen (array);//don't; ?
for(i=0; iFor (j=n - I - 1; J> 0; J -)
{
If (array [j] & gt; Array [1])
{
* p=array [j]; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related