Update status to 1-22
This commit is contained in:
parent
d7ad1d229b
commit
fdf2e04a3f
|
@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.0)
|
|||
project(learningc LANGUAGES C)
|
||||
|
||||
set(CHAPTER 1)
|
||||
set(EXERCISE 21)
|
||||
set(EXERCISE 22)
|
||||
|
||||
add_executable(learningc chapters/${CHAPTER}/exercises/${EXERCISE}.c)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#include<stdio.h>
|
||||
#include <stdio.h>
|
||||
#include "shared/limits.h"
|
||||
#include "shared/functions.h"
|
||||
#include "shared/functions/entab.c"
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
#include <stdio.h>
|
||||
#include "shared/functions.h"
|
||||
#include "shared/functions/fold.c"
|
||||
|
||||
int main() {
|
||||
int len;
|
||||
char line[MAXLINE];
|
||||
while ((len = fold(line,MAXLINE, 30)) > 0) {
|
||||
printf("%s", line);
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -6,3 +6,4 @@ void copy(char to[], char from[]);
|
|||
int getlines(char line[], int maxline);
|
||||
int detab(char s[],int lim, int col);
|
||||
int entab(char s[], int lim, int col);
|
||||
int fold(char s[], int lim, int cpr);
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int fold(char s[], int lim, int cpr) {
|
||||
int c, i;
|
||||
for (i=0; i < lim-1 && i<cpr && (c=getchar())!=EOF && c!='\n';) {
|
||||
if (i != 0 || (c != ' ' && c != '\t')) {
|
||||
s[i] = c;
|
||||
++i;
|
||||
}
|
||||
}
|
||||
for (;i > 0 && (s[i-1] == ' ' || s[i-1] == '\t'); i--);
|
||||
if (i > 0) {
|
||||
s[i] = '\n';
|
||||
s[i+1] = '\0';
|
||||
} else {
|
||||
s[i] = '\0';
|
||||
}
|
||||
return i;
|
||||
}
|
Loading…
Reference in New Issue