Programm
-
Hallo Leute habe ein kleines Problem schaut es euch mal an. In der Funktion setzen() hat es ein Problem.
Ich habe hier verschachtelte Strukturen.
Habe eine txt. Datein wo drinsteht zb.:4566 => Buchnummer
4 => Ausborgtyp(2 oder 4 = Ausleihdauer in Wochen, N wenn es nicht verliehen werden kann
usw. wie es in der Struktur angegeben ist.Ich lese aus der Textdatei heraus wenn ich ausborgtyp ausgeben will kommt bei mir folgendes Zeichen: ∏.
Könnt ihr mir helfen.
Mfg. gesi#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
#include "ConsoleFunctions.h"typedef struct{
int day;
int month;
int year;
}back;typedef struct{
char street_housenr[50];
int plz;
char place[50];
}wohndaten;typedef struct{
char fname[50];
char vname[50];
}persondaten;typedef struct{
char ausweisnr[7];
persondaten name;
wohndaten adresse;
back backdate;
}ausleih;typedef struct{
char s1[15];
char s2[15];
char s3[15];
}s;typedef struct{
char autor1[50];
char autor2[50];
}aut;typedef struct{
int booknr;
char ausborgtyp;
char title[50];
aut autoren;
int erscheinungsjahr;
char verlag[50];
s schlagwort;
ausleih ausleihdaten;
}book;int allocate(book **b);
int setzen(book *b, char filename[]);
int anz_verlag(book *b);
int output_title(book *b);int main(int argc, char **argv){
char eingabefile[30], hilf[50], *eptr=NULL;
int i=0, menu=0;
book *bu;printf("Bitte geben Sie den Filename ein: ");
gets(eingabefile);allocate(&bu);
setzen(bu, eingabefile);//clrscr();
printf("(1)..........Anzahl der Verlage eines Buches\n");
printf("(2)..........Ausgabe aller Buechertitel\n\n\n");printf("Welchen Menuepunkt wollen Sie ausfuehren: ");
gets(hilf);
menu=strtol(hilf,&eptr,10);
if((hilf==eptr)||(*eptr!='\0')){
printf("\nFehler\n");
exit(1);
}switch(menu){
case 1:
anz_verlag(bu);
break;
case 2:
output_title(bu);
break;
}return 0;
}int allocate(book **b){
if((*b=(bookcalloc(50, sizeof(book *)))==NULL){
printf("\nError: Speicherplatz konnte nicht reserviert werden\n");
}
return 0;
}int setzen(book *b, char filename[]){
int i=0, j=0, le=0;
char filedata[1000][1000], hilf[1000], *eptr=NULL, hilf1[1000];
FILE *fp=NULL;fp=fopen(filename,"rt");
while((fgets(hilf,sizeof(hilf)-1,fp))!=NULL){
if(hilf[strlen(hilf)-1]=='\n'){
hilf[strlen(hilf)-1]='\0';
}
strcpy(filedata[i], hilf);
i++;}
for(i=0; i<40; i++){
b[i].booknr=strtol(filedata[j], &eptr, 10);
j++;
b[i].ausborgtyp=(char)filedata[j];
j++;
strcpy(b[i].title, filedata[j]);
j++;
strcpy(b[i].autoren.autor1, filedata[j]);
j++;
strcpy(b[i].autoren.autor2, filedata[j]);
j++;
b[i].erscheinungsjahr=strtol(filedata[j], &eptr, 10);
j++;
strcpy(b[i].verlag, filedata[j]);
j++;
strcpy(b[i].schlagwort.s1, filedata[j]);
j++;
strcpy(b[i].schlagwort.s2, filedata[j]);
j++;
strcpy(b[i].schlagwort.s3, filedata[j]);
j++;
strcpy(b[i].ausleihdaten.ausweisnr, filedata[j]);
j++;
strcpy(b[i].ausleihdaten.name.fname, filedata[j]);
j++;
strcpy(b[i].ausleihdaten.name.vname, filedata[j]);
j++;
strcpy(b[i].ausleihdaten.adresse.street_housenr, filedata[j]);
j++;
b[i].ausleihdaten.adresse.plz=strtol(filedata[j], &eptr, 10);
j++;
strcpy(b[i].ausleihdaten.adresse.place, filedata[j]);
j++;
b[i].ausleihdaten.backdate.day=strtol(filedata[j], &eptr, 10);
j++;
b[i].ausleihdaten.backdate.month=strtol(filedata[j], &eptr, 10);
j++;
b[i].ausleihdaten.backdate.year=strtol(filedata[j], &eptr, 10);
j++;}
//printf("%c", b[0].ausborgtyp);
fclose(fp);
return 0;
}int anz_verlag(book *b){
int i=0, anzverlag=0;
char verlag[100];clrscr();
printf("Verlag: ");
gets(verlag);for(i=0;i<40;i++){
if(strcmp(verlag, b[i].verlag)==0){
anzverlag++;
}
}printf("Anzahl der Buecher eines Verlages: %d", anzverlag);
return 0;
}int output_title(book *b){
int i=0, j=0;
char hilf[50], *eptr=NULL;clrscr();
for(i=0;i<40;i++){
printf("%d.Title des Buecher: ", i+1);
puts(b[i].title);
puts(b[i].schlagwort.s1);
puts(b[i].schlagwort.s2);
puts(b[i].schlagwort.s3);}
return 0;
}
-
Toll!!!!
Und sagst Du uns jetzt auch noch was für ein Problem?
-
Ich will den Ausborgtyp aus der Datei herauslesen und am Bildschirm ausgeben.
Aber statt dem Zeichen N kommt immer so ein ∏ Zeichen.
Vielleicht hat es bei der Konvertierung was, aber er gibt mir auch keinen Fehler aus.
Mfg. gesi
-
Hast Du es schon mal mit debuggen versucht? Das ganze ist übrigens miserabel... feste arrays, wenn Du die größe im vorraus nicht kennst ist sehr schlecht... Schau Dir mal die STL an oder mache es etwas dynamischer (new).