SHARE
TWEET

Untitled

a guest Jun 26th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*******************************
  2.  * Author:                     *
  3.  * Date: 4/22/2019             *
  4.  * Purpose: Book exercise      *
  5.  *******************************/
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. #define MAX_LINE 1000
  11.  
  12. int get_line(char line[], int maxline);
  13. void copy(char to[], char from[]);
  14.  
  15. /*Print longest input line*/
  16. int main()
  17. {
  18.     int len;    //Current line length
  19.     int max;    //Maximum length seen so far
  20.  
  21.     char line[MAX_LINE];        //Current input line
  22.     char longest[MAX_LINE];     //Longest line saved here
  23.  
  24.     max = 0;
  25.  
  26.     //While input length is greater than 0
  27.     while((len = get_line(line, MAX_LINE)) > 0)
  28.     {
  29.         //If current string is longer than max
  30.         if (len > max)
  31.         {
  32.             max = len;              //Assign new max value
  33.             copy(longest, line);    //Replace longest string value with current string
  34.         }
  35.     }
  36.  
  37.     if (max > 0)
  38.     {
  39.         printf("%s", longest);
  40.     }
  41.     return 0;
  42. }
  43.  
  44. int get_line(char s[], int lim)
  45. {
  46.     int c, i;
  47.  
  48.     /*i = 0; i less than limit - 1 *and* input is not EOF *and* input is not enter key */
  49.     for (i=0; i<lim - 1 && (c=getchar())!=EOF && c!='n'; i++)
  50.     {
  51.         s[i] = c; // input array position i is = input
  52.     }
  53.  
  54.     //Once enter key is hit
  55.     if (c == 'n')
  56.     {
  57.         s[i] = c;   //Add enter key 'n' onto array
  58.         i++;        //Incr i so that last char can be '' later
  59.     }
  60.  
  61.     s[i] = '';    //The last spot on char array is ''
  62.     return i;
  63. }
  64.  
  65. void copy(char to[], char from[])
  66. {
  67.     int i;
  68.  
  69.     i = 0;
  70.  
  71.     //Assign from[i] to to[i] until null terminator
  72.     while((to[i] = from[i]) != '')
  73.     {
  74.         i++;
  75.     }
  76. }
  77.      
  78. int add_num(int num1);
  79. main()
  80. {
  81.     int x = 5;
  82.     add_num(x);
  83.     printf("%d", x);
  84. }
  85.  
  86. int add_num(int num1)
  87. {
  88.     num1 += 5;
  89.     return num1;
  90. }
  91.      
  92. x = add_num(x);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top