diff --git a/vagen_till_c/ch2/exercise7.c b/vagen_till_c/ch2/exercise7.c new file mode 100644 index 0000000..3fb567f --- /dev/null +++ b/vagen_till_c/ch2/exercise7.c @@ -0,0 +1,30 @@ +#include + +/* My solution to exercise 7 chapter 2 from "Vägen till C". + * Not done yet... + */ + +int main() +{ + char c, all[100]; + int i = 0; + int j= 0; + + while ((c = getchar()) != EOF) + { + all[i] = c; + i++; + } + all[i] = '\0'; + + while (all[j] != EOF) + { + if (all[i] == ' ' || all[i] == '\n') + { + putchar('\n'); + } + putchar(all[j]); + j++; + } + putchar('\n'); +} diff --git a/vagen_till_c/ch2/exercise7_ver2.c b/vagen_till_c/ch2/exercise7_ver2.c new file mode 100644 index 0000000..5ecb55a --- /dev/null +++ b/vagen_till_c/ch2/exercise7_ver2.c @@ -0,0 +1,12 @@ +#include + +/* Another solution to to exercise 7, chapter 2, "Vägen till C". + * Not done yet... + */ + +int main() +{ + char c[100]; + scanf("%100[0-9a-zA-Z ]", c); + printf("%s\n", c); +}