Started working on exercise 7
This commit is contained in:
parent
0dbfe8f78a
commit
b86ee577dc
30
vagen_till_c/ch2/exercise7.c
Normal file
30
vagen_till_c/ch2/exercise7.c
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* 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');
|
||||||
|
}
|
12
vagen_till_c/ch2/exercise7_ver2.c
Normal file
12
vagen_till_c/ch2/exercise7_ver2.c
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user