Function and array of characters

/ Function *********** ************* /
#include <stdio.h>
int power (int m, n-int);
/ * * function test power /
main ()
{
 int I;
 for (I = 0; I <10; I ++)
  the printf ( "% D% D% D \ n-", I, Power (2, I), Power (-3, I ));
 return 0;
}
/ * Power function: find base number n power; wherein n> = 0 * /
int Power (int Base, int n)
{
 int I, P;
 P =. 1;
 for (I =. 1 ; <= n-I; I ++)
  P = P * Base;
 return P;
}
 This function is no need to explain too much place briefly about the formal and actual parameters of it. the first statement power function: int power (int base, int n) declare type of parameter name and type of the result returned by the function. The parameters used in the name of power function of the internal power function only effective for any other function is not visible: Additional functions can be used with the same parameter name without causing a conflict. I and p are such variables: independent power function of i and i in the main function.
 We usually variable within the function definition in parentheses appear in the list called formal parameters, and the function call with formal parameter corresponding value is called the actual parameters.
/ ************************************************* *** /
/ ************************* character array *************************************** / 
#include <stdio.h>
maximum length #define MAXLINE 1000 / * row * allowable input /
int getline(char line[], int maxline);
void copy(char to[], char from[]);
/*打印最长的输入行*/
main()
{
 int len; /*当前行长度*/
 int max; /*目前为止发现的最长行的长度*/
 char line[MAXLINE];  /*当前的输入行*/
 char longest[MAXLINE]; /*用于保存最长的行*/
 
 max = 0;
 while((len = getline(line,MAXLINE)) > 0)
  if(len > max)
  {
   max = len;
   copy(longest, line);
  }
 if(max > 0) /*存在这样的行*/
  printf("%s",longest);
 return 0; 
 
 /*getline函数:将一行读入到s中并返回其长度*/
 int getline(char s[], int lim)
 {
  int c, i;
  for(i=0;i<lim-1 && (c=getchar())!=EOF && c!='\n';++i)
   s[i] = c;
  if(c == '\n')
  {
   s[i] = c;
   ++i;
  }
  s[i]='\0';
  return i;
 }
 
 /*copy函数:将from复制到to;这里假定to足够大*/
 void copy(char to[], char from[])
 {
  int i;
  i=0;
  while((to[i] = from[i]) != '\0')
   ++i;
 }
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Guess you like

Origin www.cnblogs.com/TheFly/p/11827038.html