From d6e0262ddbbbea7d207631a7889bb2e83a11d79d Mon Sep 17 00:00:00 2001 From: zlg Date: Thu, 28 Feb 2013 00:03:30 -0600 Subject: Change 2-02's solution to a while loop A recursive function is a bit much for something that simple. --- ch2/2-02_no-logical-operators.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'ch2') diff --git a/ch2/2-02_no-logical-operators.c b/ch2/2-02_no-logical-operators.c index 6fea5d6..6fa1601 100644 --- a/ch2/2-02_no-logical-operators.c +++ b/ch2/2-02_no-logical-operators.c @@ -9,8 +9,9 @@ * * for (i=0; i < lim - 1 && (c = getchar()) != '\n' && c != EOF) * i++; + * ) * - * Answer: A recursive function should do the job. I think... + * Answer: A while loop and a few 'if's should do it. * */ @@ -20,25 +21,20 @@ char test[LIMIT] = ""; int i = 0; int c; -void save_string(char s[]) { - if (i < LIMIT - 1) { +int main() { + while (i < LIMIT - 1) { c = getchar(); if (c != '\n') { if (c != EOF) { - s[i] = c; + test[i] = c; i++; } else { - return; + break; } } else { - return; + break; } - save_string(s); } -} - -int main() { - save_string(test); printf("%s\n", test); return 0; } -- cgit v1.2.3-70-g09d2 vgstash/refs/?h=v0.3b5&id=7f735dbe7544bf2837b1fa5fac38d3f001a8bb99'>refslogtreecommitdiff
path: root/scripts/helpers.sh (unfollow)
AgeCommit message (Collapse)AuthorFilesLines
2016-10-21Add quotes to correct behavior for arglistZe Libertine Gamer1-1/+1
2016-10-14updater.sh: add recursion, error handlingZe Libertine Gamer1-43/+101
2016-10-14Correct pipe-handling behaviorZe Libertine Gamer1-1/+9
2016-10-12Clarify a method to move between platformsZe Libertine Gamer1-2/+5
Also correct a typo.