|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
//benutzte include-Dateien #include <stdio.h> // Standardfunktionen Ein- und Ausgabe #include <conio.h> // Standardfunktionen Tastatur und Bildschirm #include <math.h> // mathematische Standardfunktion #include <string.h> // #include "strukturen.h" // Strukturen des Fragenpools und Prototypen int main (void) { struct leicht cont; printf("1. Frage 100 Eturo:\n\n"); printf("%s\n\n",cont.frage1); printf("%s\t\t",cont.antwort1_1); printf("%s\t\t",cont.antwort1_2); printf("\n%s\t\t",cont.antwort1_3); printf("%s\t",cont.antwort1_4); getch(); return 0; } |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
#include <stdio.h> #include <conio.h> #include <string.h> struct leicht { char frage1[50]; char antwort1_1[30]; char antwort1_2[30]; char antwort1_3[30]; char antwort1_4[30]; char frage2[50]; char antwort2_1[30]; char antwort2_2[30]; char antwort2_3[30]; char antwort2_4[30]; char frage3[50]; char antwort3_1[30]; char antwort3_2[30]; char antwort3_3[30]; char antwort3_4[30]; char frage4[50]; char antwort4_1[30]; char antwort4_2[30]; char antwort4_3[30]; char antwort4_4[30]; }leicht; struct mittel { char frage1[50]; char antwort1_1[30]; char antwort1_2[30]; char antwort1_3[30]; char antwort1_4[30]; char frage2[50]; char antwort2_1[30]; char antwort2_2[30]; char antwort2_3[30]; char antwort2_4[30]; char frage3[50]; char antwort3_1[30]; char antwort3_2[30]; char antwort3_3[30]; char antwort3_4[30]; char frage4[50]; char antwort4_1[30]; char antwort4_2[30]; char antwort4_3[30]; char antwort4_4[30]; }mittel; struct schwer { char frage1[50]; char antwort1_1[30]; char antwort1_2[30]; char antwort1_3[30]; char antwort1_4[30]; char frage2[50]; char antwort2_1[30]; char antwort2_2[30]; char antwort2_3[30]; char antwort2_4[30]; char frage3[50]; char antwort3_1[30]; char antwort3_2[30]; char antwort3_3[30]; char antwort3_4[30]; char frage4[50]; char antwort4_1[30]; char antwort4_2[30]; char antwort4_3[30]; char antwort4_4[30]; }; int main (void) { struct leicht cont; strcpy(cont.frage1,"text text text text"); strcpy(cont.antwort1_1,"a) text"); strcpy(cont.antwort1_2,"b) text"); strcpy(cont.antwort1_3,"c) text"); strcpy(cont.antwort1_4,"d) text"); getch(); return 0; } |
|
|
C Quellcode |
1 |
Fehler 7 error C2084: Funktion 'int main(void)' hat bereits einen Funktionsrumpf |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
struct schwer { char frage1[50] = "text"; char antwort1_1[30] = "text"; char antwort1_2[30] = "text"; char antwort1_3[30] = "text"; char antwort1_4[30] = "text"; char frage2[50] = "text"; char antwort2_1[30] = "text"; char antwort2_2[30] = "text"; char antwort2_3[30] = "text"; char antwort2_4[30] = "text"; char frage3[50] = "text"; char antwort3_1[30] = "text"; char antwort3_2[30] = "text"; char antwort3_3[30] = "text"; char antwort3_4[30] = "text"; char frage4[50] = "text"; char antwort4_1[30] = "text"; char antwort4_2[30] = "text"; char antwort4_3[30] = "text"; char antwort4_4[30] = "text"; }; |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
struct schwer { schwer(); char frage1[50]; char antwort1_1[30]; char antwort1_2[30]; char antwort1_3[30]; char antwort1_4[30]; char frage2[50]; char antwort2_1[30]; char antwort2_2[30]; char antwort2_3[30]; char antwort2_4[30]; char frage3[50]; char antwort3_1[30]; char antwort3_2[30]; char antwort3_3[30]; char antwort3_4[30]; char frage4[50]; char antwort4_1[30]; char antwort4_2[30]; char antwort4_3[30]; char antwort4_4[30]; }; void schwer::schwer (void) { strcpy(frage1,"text text text text"); strcpy(antwort1_1,"a) text"); strcpy(antwort1_2,"b) text"); strcpy(antwort1_3,"c) text"); strcpy(antwort1_4,"d) text"); } |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 |
struct leicht { char frage1[50] = "Text"; char antwort1_1[30] = "Text"; char antwort1_2[30] = "Text"; char antwort1_3[30] = "Text"; char antwort1_4[30] = "Text"; }leicht; |
Quoted
Fehler 1 error C2864: "leicht::frage1": Nur statische konstante integrale Datenmember können innerhalb einer Klasse initialisiert werden.
Fehler 2 error C2864: "leicht::antwort1_1": Nur statische konstante integrale Datenmember können innerhalb einer Klasse initialisiert werden.
Fehler 3 error C2864: "leicht::antwort1_2": Nur statische konstante integrale Datenmember können innerhalb einer Klasse initialisiert werden.
Fehler 4 error C2864: "leicht::antwort1_3": Nur statische konstante integrale Datenmember können innerhalb einer Klasse initialisiert werden.
Fehler 5 error C2864: "leicht::antwort1_4": Nur statische konstante integrale Datenmember können innerhalb einer Klasse initialisiert werden.
Quoted from ""Chen""
Wenn ich es so mache:
![]()
C Quellcode
1 2 3 4 5 6 7 8 9 struct leicht { char frage1[50] = "Text"; char antwort1_1[30] = "Text"; char antwort1_2[30] = "Text"; char antwort1_3[30] = "Text"; char antwort1_4[30] = "Text"; }leicht;
kommt folgednde Fehlermeldung:
Quoted
Fehler 1 error C2864: "leicht::frage1": Nur statische konstante integrale Datenmember können innerhalb einer Klasse initialisiert werden.
Fehler 2 error C2864: "leicht::antwort1_1": Nur statische konstante integrale Datenmember können innerhalb einer Klasse initialisiert werden.
Fehler 3 error C2864: "leicht::antwort1_2": Nur statische konstante integrale Datenmember können innerhalb einer Klasse initialisiert werden.
Fehler 4 error C2864: "leicht::antwort1_3": Nur statische konstante integrale Datenmember können innerhalb einer Klasse initialisiert werden.
Fehler 5 error C2864: "leicht::antwort1_4": Nur statische konstante integrale Datenmember können innerhalb einer Klasse initialisiert werden.
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#include <stdlib.h> #include <string.h> #include <assert.h> typedef struct _question_t { char* question; unsigned int answerCount; char** answers; } question_t; question_t* newQuestion (unsigned int nNumberOfAnswers) { question_t* pQuestion; unsigned int i; // added assert (nNumberOfAnswers > 0); pQuestion = (question_t*) malloc (sizeof (question_t)); pQuestion->question = NULL; pQuestion->answerCount = nNumberOfAnswers; pQuestion->answers = (char**) malloc (nNumberOfAnswers * sizeof (char*)); for (i = 0; i < nNumberOfAnswers; ++i) // added pQuestion->answers[i] = NULL; // added return pQuestion; } void deleteQuestion (question_t* pQuestion) { if (pQuestion) { unsigned int i; if (pQuestion->question) free (pQuestion->question); for (i = 0; i < pQuestion->answerCount; ++i) if (pQuestion->answers[i]) free (pQuestion->answers[i]); free (pQuestion->answers); } } void setQuestion (question_t* pQuestion, const char* pString) { assert (pQuestion); if (pQuestion->question) free (pQuestion->question); pQuestion->question = strdup (pString); } void setAnswer (question_t* pQuestion, unsigned int nIndex, const char* pString) { assert (pQuestion); assert (nIndex < pQuestion->answerCount); if (pQuestion->answers[nIndex]) free (pQuestion->answers[nIndex]); pQuestion->answers[nIndex] = strdup (pString); } |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 |
question_t* p = newQuestion (4); setQuestion (p, "Wie?"); // war mal ein Fehler in dieser Zeile setAnswer (p, 0, "a"); setAnswer (p, 1, "a"); setAnswer (p, 2, "a"); setAnswer (p, 3, "a"); /* ... */ deleteQuestion (p); |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <stdio.h> // Standardfunktionen Ein- und Ausgabe #include <conio.h> // Standardfunktionen Tastatur und Bildschirm #include <math.h> // mathematische Standardfunktion #include <string.h> // #include "struct_daten.h" // Strukturen des Fragenpools und Prototypen int main (void) { printf("\n\t\tWer wird Millionaer?"); question_t* p = newQuestion (4); p->setQuestion ("Wie geht das?"); setAnswer (p, 0, "a)"); setAnswer (p, 1, "b)"); setAnswer (p, 2, "c)"); setAnswer (p, 3, "d)"); /* ... */ deleteQuestion (p); getch(); return 0; } |
|
|
C Quellcode |
1 |
Fehler 3 error C2039: 'setQuestion': Ist kein Element von '_question_t' |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
struct fr_leicht_1 { char frage1[50]; char antwort1_1[30]; char antwort1_2[30]; char antwort1_3[30]; char antwort1_4[30]; }question_l; struct fr_mittel_1 { char frage6[50]; char antwort6_1[30]; char antwort6_2[30]; char antwort6_3[30]; char antwort6_4[30]; }question_m; . . . |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 |
. . . typ feld_leicht[5]; feld_leicht[0] = question_l.fr_leicht_1; feld_leicht[1] = question_l.fr_leicht_2; feld_leicht[2] = question_l.fr_leicht_3; feld_leicht[3] = question_l.fr_leicht_4; feld_leicht[4] = question_l.fr_leicht_5; . . . |