Over 80

Apr 27, 2015 at 1:32pm
Hello,

I need to print all input lines longer than 80 characters.
So if I understand it right, shouldn`t the pseudocode be something like that?

1. move input data into a buffer
2. if the buffer is full get that data (save it)
3. copy it
4. print it.

Any suggestions are welcome, thanks.
Apr 27, 2015 at 2:24pm
your pseudocode does not perform any check on the length of the line

(2) ¿full? ¿save where? ¿what for?
(3) ¿copy where? ¿what for?
Apr 27, 2015 at 2:26pm
WHILE read line
  IF line is long
  THEN print line

Easy with std::getline and std::string.

Easy with existing application (grep).
Apr 27, 2015 at 3:22pm
¿is there a flag for counting or you mean .{80,}?
Last edited on Apr 27, 2015 at 3:23pm
Apr 27, 2015 at 6:15pm
Here are a couple of programming ideas

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

*/ read a buffer/*

int readbuf(char * pbuf[ ])
{

   int i = 0;
   char c;


    while (i < MINLENGTH) {
        c = getchar();
        if (c == EOF) return -1;
        if (c == '\n') return 0;
        buffer[i++] = c;
    }
    return 1;
}
 */



Last edited on Apr 27, 2015 at 9:34pm
Apr 28, 2015 at 12:55pm
Forget what I posted above. I see no need for copying here. I can`t really get keskiverto`s point here. What use is cstring here?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#define MAXLINE 1000     /* maximum input line size */

int getline(char line[ ], int maxline);


/* print input lines longer than 80 chars*/

int getline(char line[ ], int maxline[ ]);

 

int main()
{
	int len;
	char line[MAXLINE];
	
	
	max = 0;
	while((len = getline(line, MAXLINE)) > 0) {
		if (len > 80)  {
		
		 printf("%s", line);
			
		}
       }
               
  return 0;

}	
		

                   
                     
		    

               
}
	
	int getline(char s[ ], int lim)
		
	{
		int c, i;
		
		for (i=0; i<lim-1 && (c = getchar()) != EOF && c!= '\n'; ++i)
		s[i] = c;
		
		s[i] = '\0';
		return i;
	}
	
	
	
	
Last edited on Apr 28, 2015 at 4:02pm
Topic archived. No new replies allowed.