Systemnahe Programmierung in C: Sprung-Anweisungen |
|
1{
2
3 ...
4
5 for (cnt = 0;
6 cnt < 50;
7 ++cnt)
8 {
9 c = getchar();
10 if (c == '\n')
11 break;
12
13 /* verarbeite andere Zeichen */
14 {
15 ...;
16 }
17 } /* end for */
18
19 /* break springt hierher */
20
21 ...
22
23}
|
1#include <stdio.h>
2#include <ctype.h>
3
4int
5modMakeInt (void)
6{
7 int num = 0, digit;
8
9 while ((digit = getchar ()) != '\n')
10 {
11 if (! isdigit (digit))
12 continue;
13
14 num = num * 10;
15 num = num + (digit - '0');
16 }
17
18 return num;
19}
|
1#include <stdio.h>
2#include <ctype.h>
3
4int
5modMakeInt (void)
6{
7 int num = 0, digit;
8
9 while ((digit = getchar ()) != '\n')
10 {
11 if (isdigit (digit))
12 {
13 num = num * 10;
14 num = num + (digit - '0');
15 }
16 }
17
18 return num;
19}
|
1#include <stdio.h>
2#include <math.h>
3
4int
5main (void)
6{
7 int num;
8
9 scanf ("%d", &num);
10 if (num < 0)
11 goto badVal;
12
13 else /* redundant */
14 {
15 printf ("Die Wurzel ist : %f\n", sqrt (num));
16 goto end;
17 }
18
19badVal:
20 printf ("Fehler: Die Zahl ist negativ.\n");
21 return 1;
22
23end:
24 return 0;
25}
|
Letzte Änderung: 11.01.2007 | © Prof. Dr. Uwe Schmidt |