C language function encyclopedia (s) (1)

Source: Internet
Author: User
Tags flush integer printf stdin

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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.