Spacy Bar
05.07.2014, 19:22
Hallo Community,
Ich habe mal auf dem PC ein Programm geschrieben, dass Zahlenwerte in einer Verketteten Liste speichert. Ich dachte mir, dass kann der Robby auch nur Zahlen sind witzlos, es müssen schon char-Arrays/Strings sein. Das ganze endete in einem Zeigergewirr mit Strukturgewirr verknüpft. Ich hoffe ihr habt eine Lösung für mein Problem, ich habe 'ne ganze menge Zeit rein investiert.
#include "asuro.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct knoten {
char wort[16];
struct knoten *next;
};
typedef struct knoten Knoten_t;
typedef struct knoten* KnotenPtr_t;
KnotenPtr_t anfang = NULL;
void einfuegenknoten( KnotenPtr_t neu ) {
KnotenPtr_t hilfZeiger;
if( anfang == NULL ) {
anfang = neu;
neu->next = NULL;
}
else {
hilfZeiger = anfang;
while(hilfZeiger->next != NULL) hilfZeiger = hilfZeiger->next;
hilfZeiger->next = neu;
neu->next = NULL;
}
}
void neuerKnoten(void){
KnotenPtr_t neu = malloc(sizeof(Knoten_t));
if( neu == NULL){
SerWrite("Speicher ist voll/Kein Speicher vorhanden!\n\r",45);
return;
}
SerWrite("Wert für Knoten eingeben:\n\r",26);
do { SerRead(wort[16] ,15,0);
} while( getchar()!='\n');
}
void loescheKnoten(char txt[]){
KnotenPtr_t hilfZeiger1;
KnotenPtr_t hilfZeiger2;
if(anfang != NULL){
char tmp[] = anfang->wort
else if( strcmp(txt[], tmp[]) == 0 ){
hilfZeiger1 = anfang->next;
free(anfang);
anfang = hilfZeiger1;
}
else {
hilfZeiger1 = anfang;
while(hilfZeiger1->next != NULL){
hilfZeiger2 = hilfZeiger1->next;
char tmp2[] = hilfZeiger2->wort[];
if( strcmp( txt[] , tmp2[]) == 0 ){
hilfZeiger1->next = hilfZeiger2->next;
break;
}
}
}
}
}
void knotenAuflisten(void){
KnotenPtr_t hilfZeiger = anfang;
while( hilfZeiger != NULL ){
char out[16] = hilfZeiger->wort[16];
SerWrite(out, 16);
hilfZeiger = hilfZeiger->next;
}
}
int main(void){
while(1){
char wahl[2] = '\0';
char tmp[16];
SerWrite("-a- Neues Wort hinzufügen\n\r", 28)
SerWrite("-b- Wort löschen\n\r",19);
SerWrite("-c- Alle Worte auflisten\n\r",27);
SerWrite("Ihre Wahl:\n\r",13);
SerRead(wahl, 1,0);
if( strcmp(wahl, 'a') == 0){
neuerKnoten();
break;
}
else if(strcmp(wahl, 'b')==0){
SerWrite("Wort zum löschen:\n\r",20);
SerRead(tmp, 15,0);
loescheKnoten(tmp[16]);
break;
}
else if(strcmp(wahl, 'c')==0){
knotenAuflisten();
break;
}
}
return 0;
}
Nun zur Fehlermeldung:
> "C:\ASURO_src\FirstTry\Test-all.bat"
C:\ASURO_src\FirstTry>make all
set -e; avr-gcc -MM -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=asuro.lst asuro.c \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > asuro.d; \
[ -s asuro.d ] || rm -f asuro.d
0 [main] sh 888 sync_with_child: child 5736(0x154) died before initialization with status code 0xC0000142
45612 [main] sh 888 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
set -e; avr-gcc -MM -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=test.lst test.c \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > test.d; \
[ -s test.d ] || rm -f test.d
0 [main] sh 6852 sync_with_child: child 5140(0x154) died before initialization with status code 0xC0000142
6152 [main] sh 6852 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
-------- begin --------
avr-gcc --version
avr-gcc (WinAVR 20100110) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
avr-gcc -c -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=test.lst test.c -o test.o
test.c: In function 'neuerKnoten':
test.c:32: warning: pointer targets in passing argument 1 of 'SerWrite' differ in signedness
test.c:35: warning: pointer targets in passing argument 1 of 'SerWrite' differ in signedness
test.c:36: error: 'wort' undeclared (first use in this function)
test.c:36: error: (Each undeclared identifier is reported only once
test.c:36: error: for each function it appears in.)
test.c: In function 'loescheKnoten':
test.c:45: error: invalid initializer
test.c:45: error: expected ',' or ';' before 'else'
test.c:50: error: expected '}' before 'else'
test.c:44: warning: unused variable 'tmp'
test.c:54: error: expected expression before ']' token
test.c:54: error: array subscript is not an integer
test.c:54: error: invalid initializer
test.c:55: error: expected expression before ']' token
test.c:55: error: array subscript is not an integer
test.c:55: error: array subscript is not an integer
test.c: At top level:
test.c:62: error: expected identifier or '(' before '}' token
test.c: In function 'knotenAuflisten':
test.c:67: error: invalid initializer
test.c:68: warning: pointer targets in passing argument 1 of 'SerWrite' differ in signedness
test.c: In function 'main':
test.c:75: error: invalid initializer
test.c:77: warning: pointer targets in passing argument 1 of 'SerWrite' differ in signedness
test.c:78: error: expected ';' before 'SerWrite'
test.c:79: warning: pointer targets in passing argument 1 of 'SerWrite' differ in signedness
test.c:80: warning: pointer targets in passing argument 1 of 'SerWrite' differ in signedness
test.c:81: warning: pointer targets in passing argument 1 of 'SerRead' differ in signedness
test.c:82: warning: passing argument 2 of 'strcmp' makes pointer from integer without a cast
test.c:86: warning: passing argument 2 of 'strcmp' makes pointer from integer without a cast
test.c:87: warning: pointer targets in passing argument 1 of 'SerWrite' differ in signedness
test.c:88: warning: pointer targets in passing argument 1 of 'SerRead' differ in signedness
test.c:89: warning: passing argument 1 of 'loescheKnoten' makes pointer from integer without a cast
test.c:92: warning: passing argument 2 of 'strcmp' makes pointer from integer without a cast
make: *** [test.o] Error 1
> Process Exit Code: 2
> Time Taken: 00:01
So, jetzt seit ihr dran ;)
LG
Spacy Bar
Ich habe mal auf dem PC ein Programm geschrieben, dass Zahlenwerte in einer Verketteten Liste speichert. Ich dachte mir, dass kann der Robby auch nur Zahlen sind witzlos, es müssen schon char-Arrays/Strings sein. Das ganze endete in einem Zeigergewirr mit Strukturgewirr verknüpft. Ich hoffe ihr habt eine Lösung für mein Problem, ich habe 'ne ganze menge Zeit rein investiert.
#include "asuro.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct knoten {
char wort[16];
struct knoten *next;
};
typedef struct knoten Knoten_t;
typedef struct knoten* KnotenPtr_t;
KnotenPtr_t anfang = NULL;
void einfuegenknoten( KnotenPtr_t neu ) {
KnotenPtr_t hilfZeiger;
if( anfang == NULL ) {
anfang = neu;
neu->next = NULL;
}
else {
hilfZeiger = anfang;
while(hilfZeiger->next != NULL) hilfZeiger = hilfZeiger->next;
hilfZeiger->next = neu;
neu->next = NULL;
}
}
void neuerKnoten(void){
KnotenPtr_t neu = malloc(sizeof(Knoten_t));
if( neu == NULL){
SerWrite("Speicher ist voll/Kein Speicher vorhanden!\n\r",45);
return;
}
SerWrite("Wert für Knoten eingeben:\n\r",26);
do { SerRead(wort[16] ,15,0);
} while( getchar()!='\n');
}
void loescheKnoten(char txt[]){
KnotenPtr_t hilfZeiger1;
KnotenPtr_t hilfZeiger2;
if(anfang != NULL){
char tmp[] = anfang->wort
else if( strcmp(txt[], tmp[]) == 0 ){
hilfZeiger1 = anfang->next;
free(anfang);
anfang = hilfZeiger1;
}
else {
hilfZeiger1 = anfang;
while(hilfZeiger1->next != NULL){
hilfZeiger2 = hilfZeiger1->next;
char tmp2[] = hilfZeiger2->wort[];
if( strcmp( txt[] , tmp2[]) == 0 ){
hilfZeiger1->next = hilfZeiger2->next;
break;
}
}
}
}
}
void knotenAuflisten(void){
KnotenPtr_t hilfZeiger = anfang;
while( hilfZeiger != NULL ){
char out[16] = hilfZeiger->wort[16];
SerWrite(out, 16);
hilfZeiger = hilfZeiger->next;
}
}
int main(void){
while(1){
char wahl[2] = '\0';
char tmp[16];
SerWrite("-a- Neues Wort hinzufügen\n\r", 28)
SerWrite("-b- Wort löschen\n\r",19);
SerWrite("-c- Alle Worte auflisten\n\r",27);
SerWrite("Ihre Wahl:\n\r",13);
SerRead(wahl, 1,0);
if( strcmp(wahl, 'a') == 0){
neuerKnoten();
break;
}
else if(strcmp(wahl, 'b')==0){
SerWrite("Wort zum löschen:\n\r",20);
SerRead(tmp, 15,0);
loescheKnoten(tmp[16]);
break;
}
else if(strcmp(wahl, 'c')==0){
knotenAuflisten();
break;
}
}
return 0;
}
Nun zur Fehlermeldung:
> "C:\ASURO_src\FirstTry\Test-all.bat"
C:\ASURO_src\FirstTry>make all
set -e; avr-gcc -MM -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=asuro.lst asuro.c \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > asuro.d; \
[ -s asuro.d ] || rm -f asuro.d
0 [main] sh 888 sync_with_child: child 5736(0x154) died before initialization with status code 0xC0000142
45612 [main] sh 888 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
set -e; avr-gcc -MM -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=test.lst test.c \
| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > test.d; \
[ -s test.d ] || rm -f test.d
0 [main] sh 6852 sync_with_child: child 5140(0x154) died before initialization with status code 0xC0000142
6152 [main] sh 6852 sync_with_child: *** child state waiting for longjmp
/usr/bin/sh: fork: Resource temporarily unavailable
-------- begin --------
avr-gcc --version
avr-gcc (WinAVR 20100110) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
avr-gcc -c -mmcu=atmega8 -I. -g -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-ahlms=test.lst test.c -o test.o
test.c: In function 'neuerKnoten':
test.c:32: warning: pointer targets in passing argument 1 of 'SerWrite' differ in signedness
test.c:35: warning: pointer targets in passing argument 1 of 'SerWrite' differ in signedness
test.c:36: error: 'wort' undeclared (first use in this function)
test.c:36: error: (Each undeclared identifier is reported only once
test.c:36: error: for each function it appears in.)
test.c: In function 'loescheKnoten':
test.c:45: error: invalid initializer
test.c:45: error: expected ',' or ';' before 'else'
test.c:50: error: expected '}' before 'else'
test.c:44: warning: unused variable 'tmp'
test.c:54: error: expected expression before ']' token
test.c:54: error: array subscript is not an integer
test.c:54: error: invalid initializer
test.c:55: error: expected expression before ']' token
test.c:55: error: array subscript is not an integer
test.c:55: error: array subscript is not an integer
test.c: At top level:
test.c:62: error: expected identifier or '(' before '}' token
test.c: In function 'knotenAuflisten':
test.c:67: error: invalid initializer
test.c:68: warning: pointer targets in passing argument 1 of 'SerWrite' differ in signedness
test.c: In function 'main':
test.c:75: error: invalid initializer
test.c:77: warning: pointer targets in passing argument 1 of 'SerWrite' differ in signedness
test.c:78: error: expected ';' before 'SerWrite'
test.c:79: warning: pointer targets in passing argument 1 of 'SerWrite' differ in signedness
test.c:80: warning: pointer targets in passing argument 1 of 'SerWrite' differ in signedness
test.c:81: warning: pointer targets in passing argument 1 of 'SerRead' differ in signedness
test.c:82: warning: passing argument 2 of 'strcmp' makes pointer from integer without a cast
test.c:86: warning: passing argument 2 of 'strcmp' makes pointer from integer without a cast
test.c:87: warning: pointer targets in passing argument 1 of 'SerWrite' differ in signedness
test.c:88: warning: pointer targets in passing argument 1 of 'SerRead' differ in signedness
test.c:89: warning: passing argument 1 of 'loescheKnoten' makes pointer from integer without a cast
test.c:92: warning: passing argument 2 of 'strcmp' makes pointer from integer without a cast
make: *** [test.o] Error 1
> Process Exit Code: 2
> Time Taken: 00:01
So, jetzt seit ihr dran ;)
LG
Spacy Bar