File tree Expand file tree Collapse file tree 1 file changed +28
-14
lines changed Expand file tree Collapse file tree 1 file changed +28
-14
lines changed Original file line number Diff line number Diff line change 5
5
*
6
6
* By Faisal Saadatmand
7
7
*/
8
- #include <stdio.h>
8
+
9
9
#include <ctype.h>
10
+ #include <stdio.h>
10
11
11
- #define MAXLENGTH 81
12
+ #define MAXLEN 80
13
+ #define NCHAR 6 /* number of actually printed characters */
14
+
15
+ /* inclen: increment line's length by the number of actually printed
16
+ * characters. Break the line if its too long. */
17
+ int inclen (int len , int n )
18
+ {
19
+ if ((len += n ) < MAXLEN )
20
+ return len ;
21
+ printf ("\n" );
22
+ return n ;
23
+ }
12
24
13
25
int main (void )
14
26
{
15
- char c ;
16
- int len ; /* length of currently read line */
27
+ int c ;
28
+ int len ; /* length of currently read line */
17
29
18
- for (len = 0 ; (c = getchar ()) != EOF ; len ++ ) {
19
- if (len == MAXLENGTH ) { /* simple line breaking */
20
- printf ("\n" );
21
- len = 0 ;
22
- }
23
- if (!isgraph (c )) /* print in hexadecimal */
24
- printf ("%x" , c );
25
- else
30
+ len = 0 ;
31
+ while ((c = getchar ()) != EOF )
32
+ if (!isgraph (c )) {
33
+ printf (" 0x%02o " , c ); /* replace by NCHAR hex characters */
34
+ len = inclen (len , NCHAR );
35
+ if (c == '\n' ) {
36
+ printf ("\n" ); /* break the line */
37
+ len = 0 ;
38
+ }
39
+ } else { /* graphical character */
26
40
printf ("%c" , c );
27
- }
28
- printf ( "\n" );
41
+ len = inclen ( len , 1 );
42
+ }
29
43
return 0 ;
30
44
}
You can’t perform that action at this time.
0 commit comments