Function Name: SBRK
Function: Change the space position of the data segment
Usage: char *sbrk (int incr);
program Example:
#include
#include
int main(void)
{
printf("Changing allocation with sbrk()\n");
printf("Before sbrk() call: %lu bytes free\n",
(unsigned long) coreleft());
sbrk(1000);
printf(" After sbrk() call: %lu bytes free\n",
(unsigned long) coreleft());
return 0;
}
Function Name: scanf
Function: Perform formatted input
Usage: int scanf (char *format[,argument,...]);
program Example:
#include
#include
int main (void)
{
Char label[20];
Char name[20];
int entries = 0;
int loop, age;
Double salary;
struct ENTRY_STRUCT
{
Char name[20];
int age;
float salary;
} ENTRY[20];
/* Input a label as a string of characters restricting to characters * *
printf ("\n\nplease enter a label for the chart:");
scanf ("%20s", label);
Fflush (stdin); /* Flush the input stream in case of bad input * *
/* Input number of entries as an integer * *
printf ("How many entries would there be?" (less than 20) ");
scanf ("%d", &entries);
Fflush (stdin); /* Flush the input stream in case of bad input * *
/* Input a name restricting input to only letters upper or lower case * *
for (Loop=0;loop
{
printf ("Entry%d\n", loop);
printf ("Name:");
scanf ("%[a-za-z]", entry[loop].name);
Fflush (stdin); /* Flush the input stream in case of bad input * *
/* Input an age as an integer * *
printf ("Age:");
scanf ("%d", &entry[loop].age);
Fflush (stdin); /* Flush the input stream in case of bad input * *
/* Input a salary as a float * *
printf ("Salary:");
scanf ("%f", &entry[loop].salary);
Fflush (stdin); /* Flush the input stream in case of bad input * *
}
/* Input a name, age and salary as a string, Integer, and double * *
printf ("\nplease enter your name, age and salary\n");
scanf ("%20s%d%lf", name, &age, &salary);
/* Print out the data this was input * *
printf ("\n\ntable%s\n", label);
printf (' Compiled by%s age%d $%15.2lf\n ', name, age, salary);
printf ("-----------------------------------------------------\ n");
for (Loop=0;loop
printf ("%4d | %-20s | %5d | %15.2lf\n ",
Loop + 1,
Entry[loop].name,
Entry[loop].age,
Entry[loop].salary);
printf ("-----------------------------------------------------\ n");
return 0;
}