Help me !
-
So ich häng ma wieder fest hab ne prüfungsaufgabe bekommen und irgendwo is da ein fehler drin vielleicht kann mal ja wer drüberschauen
also der fehler liegt irgendwo in der zeile 675 glaub ich weil ich immer die fehlermeldung a bekommen
// includes the allowed librarys and the definitions
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>#define SVG_HEADER "<svg width=\"%d\" height=\"%d\" xmlns=\"http://www.w3.org/2000/svg\">\n"
#define SVG_FOOTER "</svg>"#define ERROR_A "usage: ex2 -s=savefile -c=configfile\n"
#define ERROR_B "error: out of memory\n"
#define ERROR_C "error: cannot read configfile [filename]\n"
#define ERROR_D "error: invalid parameter - please enter a color code\n"#define ERR_A "warning: file [filename] exists and will be replaced. Do you want to proceed? (y/n)"
#define ERR_B "error: unknown command\n"
#define ERR_C "error: invalid parameter - please enter an integer number\n"
#define ERR_D "error: id does not exist\n"
#define ERR_E "error: id already used\n"
#define ERR_F "cannot write to savefile [filename]\n"#define PARAM_COUNT 2
#define LINE 1
#define RECT 2
#define CIRCLE 3
#define POLYGON 4
#define TEXT 5
#define MAX_POL_EL 100
#define MAX_ID_LEN 100
#define MAX_FILL_LEN 10// creates a list
typedef struct
{
void* first_element_;
void* last_element_;
int element_count_;}
List;// creates an object
typedef struct _Obj_
{
char id_[MAX_ID_LEN+2];
char type_;
struct _Obj_ *prev_;
struct _Obj_ *next_;
}
Object;// creates a line
typedef struct
{
char id_[MAX_ID_LEN+2];
char type_;
Object* prev_;
Object* next_;
int x1_;
int y1_;
int x2_;
int y2_;}
Line;// creats a rectangle
typedef struct
{
char id_[MAX_ID_LEN+2];
char type_;
Object* prev_;
Object* next_;
int x_;
int y_;
int width_;
int height_;
char fill_[MAX_FILL_LEN];
}
Rect;// creates a circle
typedef struct
{
char id_[MAX_ID_LEN+2];
char type_;
Object* prev_;
Object* next_;
int x_;
int y_;
int radius_;
char fill_[MAX_FILL_LEN];
}
Circle;//creates a Polygon
typedef struct
{
char id_[MAX_ID_LEN+2];
char type_;
Object* prev_;
Object* next_;
int x_[MAX_POL_EL];
int y_[MAX_POL_EL];
char fill_[MAX_FILL_LEN];
}
Polygon;// creates a Text
typedef struct
{
char id_[MAX_ID_LEN+2];
char type_;
Object* prev_;
Object* next_;
int x_;
int y_;
int font_;
char fill_[MAX_FILL_LEN];
char text_[100];
}
Text;// creates the config file
typedef struct
{
int OffsetX;
int OffsetY;
char Prompt[4];
int DefWidth;
int DefHeight;
int DefRad;}
Config;//-----------------------------------------------------------------------------
/// a function called appendElement
/// @ param element Pointer onto an object with the name element
/// @ param list Pointer onto a Pointer onto an oject with the name list
/// @ return an object with the name element
//Object *appendElement(Object *element, Object **list)
{
Object *element_count = *list;if(element == 0)
{
return 0;
}element->next_ = 0;
if(*list==0)
{
*list = element;
element->prev_ = 0;
return element;
}while(element_count->next_ != 0)
{
element_count = element_count->next_;
}element_count->next_ = element;
element->prev_ = element_count;return element;
}//-----------------------------------------------------------------------------
/// a function called getElement
/// @ param id Pointer onto a character with the name id
/// @ param elements Pointer onto an oject with the name elements
/// @ return is zero
//Object *getElement(char *id, Object *elements)
{
while(elements != 0)
{
if(strcmp(elements->id_, id) == 0)
{
return elements;
}
elements = elements->next_;
}
return 0;
}//-----------------------------------------------------------------------------
/// a function called readInt
/// @ param message Pointer onto a character with the name message
/// @ param target Pointer onto an integer with the name target
/// @ param def an ineteger with the name def
/// @ param exit Pointer onto a character with the name exit
//int readInt(char *message, int *target, int def, char* exit)
{
char buffer[10];while(1)
{
printf(message);
fgets(buffer, 9, stdin);// Function strcmp compares two strings (buffer and exit)
if(strcmp(buffer, exit) == 0)
{
return 0;
}if((strcmp(buffer, "\n") == 0) && (def > -1))
{
*target = def;
return 1;
}
if(sscanf(buffer, "%d", target) == 1)
{
return 1;
}printf(ERR_C);
}
}//-----------------------------------------------------------------------------
/// a function called readId
/// @ param elements Pointer onto an object with the name elements
/// @ param target Pointer a character with the name target
/// @ return not used
//void readId(Object *elements, char *target)
{
printf("id? ");
// it gets out of an inputstream (target)a signchain into the chararray
// (stdin) with max 100 signs
fgets(target, MAX_ID_LEN, stdin);while(getElement(target, elements))
{
printf(ERR_E);
printf("id? ");
fgets(target, MAX_ID_LEN, stdin);
}
}//-----------------------------------------------------------------------------
/// a function called readLine
/// @ param new_Line Pointer onto a Line with the name new_Line
/// @ return the new_line
//Line *readLine(Line *new_line)
{
readInt(" x1?", &(new_line->x1_), -1, "");
readInt(" y1?", &(new_line->y1_), -1, "");
readInt(" x2?", &(new_line->x2_), -1, "");
readInt(" y2?", &(new_line->y2_), -1, "");return new_line;
}//-----------------------------------------------------------------------------
/// a function called readRect
/// @ param new_rect Pointer onto a Rect with the name new_rect
/// @ param def_width an Integer with the name def_width
/// @ param def_height an Integer with the name def_height
/// @ return the new_rect
//Rect *readRect(Rect *new_rect, int def_width, int def_height)
{
readInt(" x?", &(new_rect->x_), -1, "");
readInt(" y?", &(new_rect->y_), -1, "");
readInt(" width?", &(new_rect->width_), def_width, "");
readInt(" height?", &(new_rect->height_), def_height, "");printf(" fill?");
scanf("%s", new_rect->fill_);return new_rect;
}//-----------------------------------------------------------------------------
/// a function called readCircle
/// @ param new_circle Pointer onto a Circle with the name new_circle
/// @ param DefRad an Integer with the name DefRad
/// @ return the new_circle
//Circle *readCircle(Circle *new_circle, int DefRad)
{
readInt(" cx?", &(new_circle->x_), -1,"");
readInt(" cy?", &(new_circle->y_), -1,"");
readInt(" radius?", &(new_circle->radius_), DefRad,"");printf(" fill?");
scanf("%s", new_circle->fill_);return new_circle;
}//-----------------------------------------------------------------------------
/// a function called readPolygon
/// @ param new_polygon Pointer onto a Polygon with the name new_polygon
/// @ return the new_polygon
//Polygon *readPolygon(Polygon *new_polygon)
{
int i = 0;
while(readInt(" x?", &(new_polygon->x_[i]), -1, "e\n"))
{
readInt(" y?", &(new_polygon->y_[i]), -1, "");
i++;
}
new_polygon->x_[i+1] = -1;printf(" fill?");
scanf("%s", new_polygon->fill_);return new_polygon;
}//-----------------------------------------------------------------------------
/// a function called readText
/// @ param new_text Pointer onto a Text with the name new_text
/// @ return the new_text
//Text *readText(Text *new_text)
{
readInt(" x?", &(new_text->x_), -1, "");
readInt(" y?", &(new_text->y_), -1, "");printf(" text?");
scanf("%s", new_text->text_);readInt(" font-size?", &(new_text->font_), -1, "");
printf(" fill?");
scanf("%s", new_text->fill_);return new_text;
}//-----------------------------------------------------------------------------
/// a function called newElement
/// @ param elements Pointer onto Pointer onto an Object with the name elements
/// @ param type Character called type
/// @ return the new_element
//Object *newElement(Object **elements, char type, Config config)
{
Object *new_element = 0;switch (type)
{
case LINE://new dynamic memory for variable new_element with the size of Line
if((new_element = malloc(sizeof(Line))) == 0)
{
return 0;
}
readId(elements, new_element->id_);
readLine((Line)new_element);
break;
case RECT:
if((new_element = malloc(sizeof(Rect))) == 0)
{
return 0;
}
readId(elements, new_element->id_);
readRect((Rect)new_element, config.DefWidth, config.DefHeight);
break;
case CIRCLE:
if((new_element = malloc(sizeof(Circle))) == 0)
{
return 0;
}
readId(elements, new_element->id_);
readCircle((Circle)new_element, config.DefRad);
break;
case POLYGON:
if((new_element = malloc(sizeof(Polygon))) == 0)
{
return 0;
}
readId(elements, new_element->id_);
readPolygon((Polygon)new_element);
break;
case TEXT:
if((new_element = malloc(sizeof(Text))) == 0)
{
return 0;
}
readId(elements, new_element->id_);
readText((Text)new_element);
break;
}
new_element->type_ = type;
appendElement((Object*)new_element, elements);return new_element;
}//-----------------------------------------------------------------------------
/// a function called editElement
/// @ param elements Pointer onto a Pointer onto an Object called elements
/// @ return the edit_element
//Object *editElement(Object **elements)
{
Object *edit_element = 0;
char edit_id[MAX_ID_LEN];printf("id? ");
// it gets out of an Inputstream (edit_id)a signchain into the chararray
//(stdin) with max 100 signs
fgets(edit_id, MAX_ID_LEN, stdin);while((edit_element = getElement(edit_id, *elements)) == 0)
{
printf(ERR_D);
printf("id? ");
fgets(edit_id, MAX_ID_LEN, stdin);
}//it compares edit_element->type_
switch (edit_element->type_)
{
case LINE:
readLine((Line*)edit_element);
break;
case RECT:
readRect((Rect*)edit_element, ((Rect*)edit_element)->width_, ((Rect*)edit_element)->height_);
break;
case CIRCLE:
readCircle((Circle*)edit_element, ((Circle*)edit_element)->radius_);
break;
case POLYGON:
readPolygon((Polygon*)edit_element);
break;
case TEXT:
readText((Text*)edit_element);
break;
}
return edit_element;
}//-----------------------------------------------------------------------------
/// a function called deleteElement
/// @ param elements Pointer onto a Pointer onto an Object called elements
/// @ return the Pointer elements
//Object *deleteElement(Object **elements)
{
Object *del_element=0;
char del_id[MAX_ID_LEN];printf("id? ");
// it gets out of an Inputstream (del_id)a signchain into the chararray
//(stdin) with max 100 signs
fgets(del_id, MAX_ID_LEN, stdin);
if(strcmp(del_id, "e\n") == 0)
{
return 0;
}del_element = getElement(del_id, *elements);
while(del_element == 0)
{
printf(ERR_D);
printf(" id?");
fgets(del_id, MAX_ID_LEN, stdin);
if(strcmp(del_id, "e\n") == 0)
{
return 0;
}del_element = getElement(del_id, *elements);
}if(del_element == *elements)
{
*elements = (*elements)->next_;
}
else if(del_element->next_ == 0)
{
(del_element->prev_)->next_ = 0;
}
else
{
(del_element->prev_)->next_ = del_element->next_;
(del_element->next_)->prev_ = del_element->prev_;
}
free(del_element);return *elements;
}//-----------------------------------------------------------------------------
/// a function called listElements
/// @ param elements Pointer onto an Object with the name elements
/// @ return not used
//void listElements(Object *elements)
{
while(elements != 0)
{
switch (elements->type_)
{
case LINE: printf("[li] %s", elements->id_);
break;
case RECT: printf("[re] %s", elements->id_);
break;
case CIRCLE: printf("[ci] %s", elements->id_);
break;
case POLYGON: printf("[po] %s", elements->id_);
break;
case TEXT: printf("[tx] %s", elements->id_);
break;
}
elements = elements->next_;
}
}//-----------------------------------------------------------------------------
/// a function called saveElements
/// @ param elemts Pointer onto an Object with the name elements
/// @ param def Pointer onto a Character with the name def
/// @ return not used
//void saveElements(Object *elements, char* def, Config conf)
{
FILE *save_file = 0;
char save_path[100];
int width, height, i = 0;printf("file? ");
//it gets out of an Inputstream(save_path)a signchain into the chararray
// (stdin) with 98 signs
fgets(save_path, 98, stdin);
if(strcmp(save_path, "\n") == 0)
{
strcpy(save_path, def);
}while((save_file = fopen(save_path, "w")) == 0)
{
printf(ERR_F);
printf(" file?");
fgets(save_path, 98, stdin);
if(strcmp(save_path, "\n") == 0)
{
strcpy(save_path, def);
}
}readInt(" width?", &width, -1, "");
readInt(" height?", &height, -1, "");fprintf(save_file, SVG_HEADER , width,height);
while(elements != 0)
{
switch (elements->type_)
{
case LINE:
fprintf(save_file,"<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\"/>\n",
((Line*)elements)->x1_+conf.OffsetX,((Line*)elements)->y1_+conf.OffsetY,
((Line*)elements)->x2_+conf.OffsetX,((Line*)elements)->y2_);
break;
case RECT:
fprintf(save_file,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\"/>\n",
((Rect*)elements)->x_+conf.OffsetX,((Rect*)elements)->y_,
((Rect*)elements)->width_, ((Rect*)elements)->height_,((Rect*)elements)->fill_);
break;
case CIRCLE:
fprintf(save_file,"<circle cx=\"%d\" cy=\"%d\" r=\"%d\" fill=\"%s\"/>\n",
((Circle*)elements)->x_+conf.OffsetX,((Circle*)elements)->y_+conf.OffsetY,
((Circle*)elements)->radius_,((Circle*)elements)->fill_);
break;
case POLYGON:
fprintf(save_file, "<polygon points= \"");
while(((Polygon*)elements)->x_[i] != -1)
{
fprintf(save_file, "%d %d ", ((Polygon*)elements)->x_[i],
((Polygon*)elements)->y_[i]);
i++;
}
fprintf(save_file, "fill=\"%s\"",((Polygon*)elements)->fill_);
fprintf(save_file, "\"/>");
break;
case TEXT:
fprintf(save_file, "<text x=\"%d\" y=\"%d\" font-size=\"%dpx\" fill=\"%s\">%s</text>\n",
((Text*)elements)->x_ + conf.OffsetX, ((Text*)elements)->y_+conf.OffsetX,
((Text*)elements)->font_, ((Text*)elements)->fill_, ((Text*)elements)->text_);
break;
}
elements = elements->next_;
}
fprintf(save_file, SVG_FOOTER);fclose(save_file);
}//-----------------------------------------------------------------------------
/// a function called quit
/// @ param elements Pointer onto an Object with the name elements
/// @ return not used
//void quit(Object* elements)
{
Object* next_element;
while(elements != 0)
{
next_element = elements->next_;
free(elements);
elements = next_element;
}
}
//-----------------------------------------------------------------------------
/// The main programm.
/// Creates in need of a configfile rectangles, lines,polygones, texts,circles
/// and saves them. These objects can be edited, deleted and lists can be
/// created. It prints an error if one occurs.
/// @ param argc used for Error A
/// @ param argv used for Error A
/// @ return will be zero
//int main(int argc, char* argv[])
{
char *config_path = 0, *save_path = 0;
FILE *config_file = 0;
Object *elements = 0;
Config config;
int i;if(argc != PARAM_COUNT = 0)
{
printf(ERROR_A);
return -1;
}
for(i = PARAM_COUNT; i>0; i--)
{
if(strncmp(argv[i], "s=", 2) == 0)
{
save_path = argv[i] + 2;
}
else if(strncmp(argv[i], "c=", 2) == 0)
{
config_path = argv[i] + 2;
}
else
{
printf(ERROR_A);
return -1;
}
}if((config_file = fopen(config_path, "r")) == 0)
{
printf(ERROR_C);
return -3;
}
fread(&config, sizeof(Config), 1,config_file);
fclose(config_file);while(1)
{
char command[10];printf(config.Prompt);
printf("> ");//fpurge(stdin);//
// it gets out of an Inputstream(command)a signchain into the chararray
// (stdin) with 9 signs
fgets(command, 9, stdin);if(strcmp(command, "line\n") == 0)
{
if(newElement(&elements, LINE, config) == 0)
{
printf(ERROR_B);
return -2;
}
}
else if(strcmp(command, "rect\n") == 0)
{
if(newElement(&elements, RECT, config) == 0)
{
printf(ERROR_B);
return -2;
}
}
else if(strcmp(command, "circle\n") == 0)
{
if(newElement(&elements, CIRCLE, config) == 0)
{
printf(ERROR_B);
return -2;
}
}
else if(strcmp(command, "polygon\n") == 0)
{
if(newElement(&elements, POLYGON, config) == 0)
{
printf(ERROR_B);
return -2;
}
}
else if(strcmp(command, "text\n") == 0)
{
if(newElement(&elements, TEXT, config) == 0)
{
printf(ERROR_B);
return -2;
}
}
else if(strcmp(command, "edit\n") == 0)
{
editElement(&elements);
}
else if(strcmp(command, "delete\n") == 0)
{
deleteElement(&elements);
}
else if(strcmp(command, "list\n") == 0)
{
listElements(elements);
}
else if(strcmp(command, "save\n") == 0)
{
saveElements(elements, save_path, config);
}
else if(strcmp(command, "quit\n") == 0)
{
quit(elements);
return 0;
}
else
{
printf("error: unknown command\n");
}
}return 0;
}
-
Ganz schlechter Trollversuch
-
????
-
Wenn ich länger für das Durchscrollen durch den Quellcode brauche, als zum Lesen der einführenden Zeilen deines Beitrags, dann ist schonmal was falsch...
Geholfen hätten eventuell die [cpp]-Tags, vor allem, da du ne Zeilennummer angibst, aber hier sicher keiner Lust hat die Zeilen durchzuzählen.
Desweiteren gibts so nette Sachen namens Debugger, das solltest du zuerst mal probieren...
Edit: Der Titel ist auch nicht gerade geschickt gewählt...
Gruß,
U-Boot
-
jo debugger hab ich ausprobier aber es lässt sich ja kompellieren aber es kommt nichts ausser der error A und es wird mir der fehler bei zeile 662 angezeigt, aber ich hab mal den ganzen qtext reingemacht weil ich mir eben nicht sicher bin ob da der fehler ist
// includes the allowed librarys and the definitions #include <stdio.h> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <string.h> #define SVG_HEADER "<svg width=\"%d\" height=\"%d\" xmlns=\"http://www.w3.org/2000/svg\">\n" #define SVG_FOOTER "</svg>" #define ERROR_A "usage: ex2 -s=savefile -c=configfile\n" #define ERROR_B "error: out of memory\n" #define ERROR_C "error: cannot read configfile [filename]\n" #define ERROR_D "error: invalid parameter - please enter a color code\n" #define ERR_A "warning: file [filename] exists and will be replaced. Do you want to proceed? (y/n)" #define ERR_B "error: unknown command\n" #define ERR_C "error: invalid parameter - please enter an integer number\n" #define ERR_D "error: id does not exist\n" #define ERR_E "error: id already used\n" #define ERR_F "cannot write to savefile [filename]\n" #define PARAM_COUNT 2 #define LINE 1 #define RECT 2 #define CIRCLE 3 #define POLYGON 4 #define TEXT 5 #define MAX_POL_EL 100 #define MAX_ID_LEN 100 #define MAX_FILL_LEN 10 // creates a list typedef struct { void* first_element_; void* last_element_; int element_count_; } List; // creates an object typedef struct _Obj_ { char id_[MAX_ID_LEN+2]; char type_; struct _Obj_ *prev_; struct _Obj_ *next_; } Object; // creates a line typedef struct { char id_[MAX_ID_LEN+2]; char type_; Object* prev_; Object* next_; int x1_; int y1_; int x2_; int y2_; } Line; // creats a rectangle typedef struct { char id_[MAX_ID_LEN+2]; char type_; Object* prev_; Object* next_; int x_; int y_; int width_; int height_; char fill_[MAX_FILL_LEN]; } Rect; // creates a circle typedef struct { char id_[MAX_ID_LEN+2]; char type_; Object* prev_; Object* next_; int x_; int y_; int radius_; char fill_[MAX_FILL_LEN]; } Circle; //creates a Polygon typedef struct { char id_[MAX_ID_LEN+2]; char type_; Object* prev_; Object* next_; int x_[MAX_POL_EL]; int y_[MAX_POL_EL]; char fill_[MAX_FILL_LEN]; } Polygon; // creates a Text typedef struct { char id_[MAX_ID_LEN+2]; char type_; Object* prev_; Object* next_; int x_; int y_; int font_; char fill_[MAX_FILL_LEN]; char text_[100]; } Text; // creates the config file typedef struct { int OffsetX; int OffsetY; char Prompt[4]; int DefWidth; int DefHeight; int DefRad; } Config; //----------------------------------------------------------------------------- /// a function called appendElement /// @ param element Pointer onto an object with the name element /// @ param list Pointer onto a Pointer onto an oject with the name list /// @ return an object with the name element // Object *appendElement(Object *element, Object **list) { Object *element_count = *list; if(element == 0) { return 0; } element->next_ = 0; if(*list==0) { *list = element; element->prev_ = 0; return element; } while(element_count->next_ != 0) { element_count = element_count->next_; } element_count->next_ = element; element->prev_ = element_count; return element; } //----------------------------------------------------------------------------- /// a function called getElement /// @ param id Pointer onto a character with the name id /// @ param elements Pointer onto an oject with the name elements /// @ return is zero // Object *getElement(char *id, Object *elements) { while(elements != 0) { if(strcmp(elements->id_, id) == 0) { return elements; } elements = elements->next_; } return 0; } //----------------------------------------------------------------------------- /// a function called readInt /// @ param message Pointer onto a character with the name message /// @ param target Pointer onto an integer with the name target /// @ param def an ineteger with the name def /// @ param exit Pointer onto a character with the name exit // int readInt(char *message, int *target, int def, char* exit) { char buffer[10]; while(1) { printf(message); fgets(buffer, 9, stdin); // Function strcmp compares two strings (buffer and exit) if(strcmp(buffer, exit) == 0) { return 0; } if((strcmp(buffer, "\n") == 0) && (def > -1)) { *target = def; return 1; } if(sscanf(buffer, "%d", target) == 1) { return 1; } printf(ERR_C); } } //----------------------------------------------------------------------------- /// a function called readId /// @ param elements Pointer onto an object with the name elements /// @ param target Pointer a character with the name target /// @ return not used // void readId(Object *elements, char *target) { printf("id? "); // it gets out of an inputstream (target)a signchain into the chararray // (stdin) with max 100 signs fgets(target, MAX_ID_LEN, stdin); while(getElement(target, elements)) { printf(ERR_E); printf("id? "); fgets(target, MAX_ID_LEN, stdin); } } //----------------------------------------------------------------------------- /// a function called readLine /// @ param new_Line Pointer onto a Line with the name new_Line /// @ return the new_line // Line *readLine(Line *new_line) { readInt(" x1?", &(new_line->x1_), -1, ""); readInt(" y1?", &(new_line->y1_), -1, ""); readInt(" x2?", &(new_line->x2_), -1, ""); readInt(" y2?", &(new_line->y2_), -1, ""); return new_line; } //----------------------------------------------------------------------------- /// a function called readRect /// @ param new_rect Pointer onto a Rect with the name new_rect /// @ param def_width an Integer with the name def_width /// @ param def_height an Integer with the name def_height /// @ return the new_rect // Rect *readRect(Rect *new_rect, int def_width, int def_height) { readInt(" x?", &(new_rect->x_), -1, ""); readInt(" y?", &(new_rect->y_), -1, ""); readInt(" width?", &(new_rect->width_), def_width, ""); readInt(" height?", &(new_rect->height_), def_height, ""); printf(" fill?"); scanf("%s", new_rect->fill_); return new_rect; } //----------------------------------------------------------------------------- /// a function called readCircle /// @ param new_circle Pointer onto a Circle with the name new_circle /// @ param DefRad an Integer with the name DefRad /// @ return the new_circle // Circle *readCircle(Circle *new_circle, int DefRad) { readInt(" cx?", &(new_circle->x_), -1,""); readInt(" cy?", &(new_circle->y_), -1,""); readInt(" radius?", &(new_circle->radius_), DefRad,""); printf(" fill?"); scanf("%s", new_circle->fill_); return new_circle; } //----------------------------------------------------------------------------- /// a function called readPolygon /// @ param new_polygon Pointer onto a Polygon with the name new_polygon /// @ return the new_polygon // Polygon *readPolygon(Polygon *new_polygon) { int i = 0; while(readInt(" x?", &(new_polygon->x_[i]), -1, "e\n")) { readInt(" y?", &(new_polygon->y_[i]), -1, ""); i++; } new_polygon->x_[i+1] = -1; printf(" fill?"); scanf("%s", new_polygon->fill_); return new_polygon; } //----------------------------------------------------------------------------- /// a function called readText /// @ param new_text Pointer onto a Text with the name new_text /// @ return the new_text // Text *readText(Text *new_text) { readInt(" x?", &(new_text->x_), -1, ""); readInt(" y?", &(new_text->y_), -1, ""); printf(" text?"); scanf("%s", new_text->text_); readInt(" font-size?", &(new_text->font_), -1, ""); printf(" fill?"); scanf("%s", new_text->fill_); return new_text; } //----------------------------------------------------------------------------- /// a function called newElement /// @ param elements Pointer onto Pointer onto an Object with the name elements /// @ param type Character called type /// @ return the new_element // Object *newElement(Object **elements, char type, Config config) { Object *new_element = 0; switch (type) { case LINE: //new dynamic memory for variable new_element with the size of Line if((new_element = malloc(sizeof(Line))) == 0) { return 0; } readId(*elements, new_element->id_); readLine((Line*)new_element); break; case RECT: if((new_element = malloc(sizeof(Rect))) == 0) { return 0; } readId(*elements, new_element->id_); readRect((Rect*)new_element, config.DefWidth, config.DefHeight); break; case CIRCLE: if((new_element = malloc(sizeof(Circle))) == 0) { return 0; } readId(*elements, new_element->id_); readCircle((Circle*)new_element, config.DefRad); break; case POLYGON: if((new_element = malloc(sizeof(Polygon))) == 0) { return 0; } readId(*elements, new_element->id_); readPolygon((Polygon*)new_element); break; case TEXT: if((new_element = malloc(sizeof(Text))) == 0) { return 0; } readId(*elements, new_element->id_); readText((Text*)new_element); break; } new_element->type_ = type; appendElement((Object*)new_element, elements); return new_element; } //----------------------------------------------------------------------------- /// a function called editElement /// @ param elements Pointer onto a Pointer onto an Object called elements /// @ return the edit_element // Object *editElement(Object **elements) { Object *edit_element = 0; char edit_id[MAX_ID_LEN]; printf("id? "); // it gets out of an Inputstream (edit_id)a signchain into the chararray //(stdin) with max 100 signs fgets(edit_id, MAX_ID_LEN, stdin); while((edit_element = getElement(edit_id, *elements)) == 0) { printf(ERR_D); printf("id? "); fgets(edit_id, MAX_ID_LEN, stdin); } //it compares edit_element->type_ switch (edit_element->type_) { case LINE: readLine((Line*)edit_element); break; case RECT: readRect((Rect*)edit_element, ((Rect*)edit_element)->width_, ((Rect*)edit_element)->height_); break; case CIRCLE: readCircle((Circle*)edit_element, ((Circle*)edit_element)->radius_); break; case POLYGON: readPolygon((Polygon*)edit_element); break; case TEXT: readText((Text*)edit_element); break; } return edit_element; } //----------------------------------------------------------------------------- /// a function called deleteElement /// @ param elements Pointer onto a Pointer onto an Object called elements /// @ return the Pointer elements // Object *deleteElement(Object **elements) { Object *del_element=0; char del_id[MAX_ID_LEN]; printf("id? "); // it gets out of an Inputstream (del_id)a signchain into the chararray //(stdin) with max 100 signs fgets(del_id, MAX_ID_LEN, stdin); if(strcmp(del_id, "e\n") == 0) { return 0; } del_element = getElement(del_id, *elements); while(del_element == 0) { printf(ERR_D); printf(" id?"); fgets(del_id, MAX_ID_LEN, stdin); if(strcmp(del_id, "e\n") == 0) { return 0; } del_element = getElement(del_id, *elements); } if(del_element == *elements) { *elements = (*elements)->next_; } else if(del_element->next_ == 0) { (del_element->prev_)->next_ = 0; } else { (del_element->prev_)->next_ = del_element->next_; (del_element->next_)->prev_ = del_element->prev_; } free(del_element); return *elements; } //----------------------------------------------------------------------------- /// a function called listElements /// @ param elements Pointer onto an Object with the name elements /// @ return not used // void listElements(Object *elements) { while(elements != 0) { switch (elements->type_) { case LINE: printf("[li] %s", elements->id_); break; case RECT: printf("[re] %s", elements->id_); break; case CIRCLE: printf("[ci] %s", elements->id_); break; case POLYGON: printf("[po] %s", elements->id_); break; case TEXT: printf("[tx] %s", elements->id_); break; } elements = elements->next_; } } //----------------------------------------------------------------------------- /// a function called saveElements /// @ param elemts Pointer onto an Object with the name elements /// @ param def Pointer onto a Character with the name def /// @ return not used // void saveElements(Object *elements, char* def, Config conf) { FILE *save_file = 0; char save_path[100]; int width, height, i = 0; printf("file? "); //it gets out of an Inputstream(save_path)a signchain into the chararray // (stdin) with 98 signs fgets(save_path, 98, stdin); if(strcmp(save_path, "\n") == 0) { strcpy(save_path, def); } while((save_file = fopen(save_path, "w")) == 0) { printf(ERR_F); printf(" file?"); fgets(save_path, 98, stdin); if(strcmp(save_path, "\n") == 0) { strcpy(save_path, def); } } readInt(" width?", &width, -1, ""); readInt(" height?", &height, -1, ""); fprintf(save_file, SVG_HEADER , width,height); while(elements != 0) { switch (elements->type_) { case LINE: fprintf(save_file,"<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\"/>\n", ((Line*)elements)->x1_+conf.OffsetX,((Line*)elements)->y1_+conf.OffsetY, ((Line*)elements)->x2_+conf.OffsetX,((Line*)elements)->y2_); break; case RECT: fprintf(save_file,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\"/>\n", ((Rect*)elements)->x_+conf.OffsetX,((Rect*)elements)->y_, ((Rect*)elements)->width_, ((Rect*)elements)->height_,((Rect*)elements)->fill_); break; case CIRCLE: fprintf(save_file,"<circle cx=\"%d\" cy=\"%d\" r=\"%d\" fill=\"%s\"/>\n", ((Circle*)elements)->x_+conf.OffsetX,((Circle*)elements)->y_+conf.OffsetY, ((Circle*)elements)->radius_,((Circle*)elements)->fill_); break; case POLYGON: fprintf(save_file, "<polygon points= \""); while(((Polygon*)elements)->x_[i] != -1) { fprintf(save_file, "%d %d ", ((Polygon*)elements)->x_[i], ((Polygon*)elements)->y_[i]); i++; } fprintf(save_file, "fill=\"%s\"",((Polygon*)elements)->fill_); fprintf(save_file, "\"/>"); break; case TEXT: fprintf(save_file, "<text x=\"%d\" y=\"%d\" font-size=\"%dpx\" fill=\"%s\">%s</text>\n", ((Text*)elements)->x_ + conf.OffsetX, ((Text*)elements)->y_+conf.OffsetX, ((Text*)elements)->font_, ((Text*)elements)->fill_, ((Text*)elements)->text_); break; } elements = elements->next_; } fprintf(save_file, SVG_FOOTER); fclose(save_file); } //----------------------------------------------------------------------------- /// a function called quit /// @ param elements Pointer onto an Object with the name elements /// @ return not used // void quit(Object* elements) { Object* next_element; while(elements != 0) { next_element = elements->next_; free(elements); elements = next_element; } } //----------------------------------------------------------------------------- /// The main programm. /// Creates in need of a configfile rectangles, lines,polygones, texts,circles /// and saves them. These objects can be edited, deleted and lists can be /// created. It prints an error if one occurs. /// @ param argc used for Error A /// @ param argv used for Error A /// @ return will be zero // int main(int argc, char* argv[]) { char *config_path = 0, *save_path = 0; FILE *config_file = 0; Object *elements = 0; Config config; int i; if(argc != PARAM_COUNT + 1) { printf(ERROR_A); return -1; } for(i = PARAM_COUNT; i>0; i--) { if(strncmp(argv[i], "s=", 2) == 0) { save_path = argv[i] + 2; } else if(strncmp(argv[i], "c=", 2) == 0) { config_path = argv[i] + 2; } else { printf(ERROR_A); return -1; } } if((config_file = fopen(config_path, "r")) == 0) { printf(ERROR_C); return -3; } fread(&config, sizeof(Config), 1,config_file); fclose(config_file); while(1) { char command[10]; printf(config.Prompt); printf("> "); //fpurge(stdin);// // it gets out of an Inputstream(command)a signchain into the chararray // (stdin) with 9 signs fgets(command, 9, stdin); if(strcmp(command, "line\n") == 0) { if(newElement(&elements, LINE, config) == 0) { printf(ERROR_B); return -2; } } else if(strcmp(command, "rect\n") == 0) { if(newElement(&elements, RECT, config) == 0) { printf(ERROR_B); return -2; } } else if(strcmp(command, "circle\n") == 0) { if(newElement(&elements, CIRCLE, config) == 0) { printf(ERROR_B); return -2; } } else if(strcmp(command, "polygon\n") == 0) { if(newElement(&elements, POLYGON, config) == 0) { printf(ERROR_B); return -2; } } else if(strcmp(command, "text\n") == 0) { if(newElement(&elements, TEXT, config) == 0) { printf(ERROR_B); return -2; } } else if(strcmp(command, "edit\n") == 0) { editElement(&elements); } else if(strcmp(command, "delete\n") == 0) { deleteElement(&elements); } else if(strcmp(command, "list\n") == 0) { listElements(elements); } else if(strcmp(command, "save\n") == 0) { saveElements(elements, save_path, config); } else if(strcmp(command, "quit\n") == 0) { quit(elements); return 0; } else { printf("error: unknown command\n"); } } return 0; }
-
Lass mich raten, du versuchst, das Programm per Doppelklick auf die .exe zu starten? Dat Ding erwartet Parameter....
-
jo das is mir klar aber es kommt da nix ich bekomm immer die meldung usage ...... -s savefile -c config...
ich starte das ding so unter der eingabeaufforderung
....\ex2 -c zb aber da bekomm ich dann wieder die meldung
-
cyberflash schrieb:
also der fehler liegt irgendwo in der zeile 675 glaub ich weil ich immer die fehlermeldung a bekommen
Selten so gelacht!
:xmas1:
-
Niemand wird hier deine zig hundert Zeilen Programme debuggen. Versuch das Problem zu reduzieren und poste einen minimalen Code, der dein Problem illustriert. Alles andere hat keinen Sinn.
btw. solltest du deine Programme lieber in kleinen Stücken programmieren. Immer einen kleinen vollständigen Teil, den du testen kannst und wenn der Teil fertig ist, dann solltest du weiter machen. Dann kommst du gar nicht dazu hier 1000 Zeilen Programme zu posten.
Und benutz vernünftige Titel, wenn du Themen erstellst. "Help me !" ist _kein_ sinnvoller Titel!