Probleme mit Eingabe / Ausgabe. Differenzen mit Tabellen
-
#include <stdio.h> #include <dos.h> #define PFAD_LEN 255 #define ZEICHEN 100000 #define ZEICHEN_DIM2 10000 #define MAX_SPALTEN 10 void wait4key(void); int eingabe(char source_pfad[PFAD_LEN],char target_pfad[PFAD_LEN]); int lesen_datei(FILE *source, char array[ZEICHEN],char source_pfad[PFAD_LEN]); void write_table(char array[ZEICHEN],char tabelle[MAX_SPALTEN][ZEICHEN_DIM2],int iSpalten); void ausgabe (char tabelle[MAX_SPALTEN][ZEICHEN_DIM2], int iSpalten); void schreiben (char tabelle[MAX_SPALTEN][ZEICHEN_DIM2], int iSpalten,FILE* target,char target_pfad[PFAD_LEN]); void abwicklung(char tabelle[MAX_SPALTEN][ZEICHEN_DIM2],char array[ZEICHEN],int iSpalten); /* wartet auf Tastendruck */ void wait4key(void){ printf("\n\n\n\t\tBitte eine Taste druecken um fortzufahren"); getchar(); } /* Eingabe des Source- und Target- Pfades ausserdem der Spaltenanzahl zur Weiterverarbeitung*/ int eingabe(char source_pfad[PFAD_LEN],char target_pfad[PFAD_LEN]){ int iSpalten; printf("\nGeben Sie die Startdatei an:_ "); gets(source_pfad); printf("\nGeben Sie die Zieldatei an:_ "); gets(target_pfad); printf("\nGeben Sie die Spaltenanzahl der Tabelle ein:_ "); scanf("%i",&iSpalten); fflush(stdin); return iSpalten; } /* Datei auslesen und in Variable schreiben */ int lesen_datei(FILE *source, char array[ZEICHEN],char source_pfad[PFAD_LEN]){ char cZeichen; int a=0; source=fopen(source_pfad, "r"); if (source==NULL){ printf("\n\nNicht existierendes Quellverzeichnis"); printf("\n\nDas Programm wird beendet"); return 1; } else{ while((cZeichen = getc(source))!=EOF){ array[a]=cZeichen; a++; } array[a]='\0'; return 0; } fclose(source); } /* Tabelle schreiben */ void write_table(char array[ZEICHEN],char tabelle[MAX_SPALTEN][ZEICHEN_DIM2],int iSpalten){ int a,b,c=0,d; /* Hier wird der eindimmensionale array, in Spalten und Zeilen aufgeteilt, um nachher selektiert werden zu können */ do{ for(a=0;a<iSpalten;a++){ while((array[c]!='\t') && (array[c]!='\n')){ for(b=0;tabelle[a][b]!='\0';b++); tabelle[a][b]=array[c]; b++; c++; } tabelle[a][b]=array[c]; c++; } } while (array[c]!='\0'); } /* Tabelle auf Bildschirm ausgeben */ void ausgabe (char tabelle[MAX_SPALTEN][ZEICHEN_DIM2], int iSpalten){ int a,b,c=0,d=0; system("cls"); do{ for (a=0;a<iSpalten;a++){ if (a==0){b=c;} if (a==1){b=d;} for (;b<ZEICHEN_DIM2;b++){ printf("%c",tabelle[a][b]); if (a==0){c++;} if (a==1){d++;} if (tabelle[a][b]=='\n' || tabelle[a][b]=='\t' || tabelle[a][b]=='\0') break; } } } while (tabelle[1][b]!='\0'); } /* Tabelle in eine Textdatei schreiben */ void schreiben (char tabelle[MAX_SPALTEN][ZEICHEN_DIM2], int iSpalten,FILE* target,char target_pfad[PFAD_LEN]){ int a,b,c=0,d=0; target=fopen(target_pfad, "w"); do{ for (a=0;a<iSpalten;a++){ if (a==0){b=c;} if (a==1){b=d;} for (;b<ZEICHEN_DIM2;b++){ fprintf(target,"%c",tabelle[a][b]); if (a==0){c++;} if (a==1){d++;} if (tabelle[a][b]=='\n' || tabelle[a][b]=='\t' || tabelle[a][b]=='\0') break; } } } while (tabelle[iSpalten-1][b]!='\0'); fclose(target); } /* Zusammenwurschteln der Angaben und Konstanten */ void abwicklung(char tabelle[MAX_SPALTEN][ZEICHEN_DIM2],char array[ZEICHEN],int iSpalten){ /* int a,b,ka,lfw; char ttnr[11]; const char aggr[3]; const char jahr[3]; int datum[10]; struct date d; getdate(&d); strcpy(aggr,"00"); strcpy(jahr,"04"); for (a=0;a<iSpalten;a++){ for (b=0;b<ZEICHEN_DIM2;b++){ tabelle[a][b]=0; } } printf("\nGeben Sie die Konstante ein:_ "); scanf("%i",&ka); fflush(stdin); printf("Datum: %.2d%.2d04", d.da_day, d.da_mon); // fprintf("",ka,ttnr,lfw,aggr,jahr); */ } int main(void){ FILE *source; FILE *target; int a,b,test; int iSpalten; char source_pfad[PFAD_LEN],target_pfad[PFAD_LEN],cZeichen; char tabelle[MAX_SPALTEN][ZEICHEN_DIM2]; char array[ZEICHEN]; printf("Excel Converter\n"); iSpalten=eingabe(source_pfad,target_pfad); test=lesen_datei(source,array,source_pfad); if (test==1){ wait4key(); return 1; } else { for (a=0;a<iSpalten;a++){ for (b=0;b<ZEICHEN_DIM2;b++){ tabelle[a][b]=0; } } write_table(array,tabelle,iSpalten); ausgabe(tabelle,iSpalten); schreiben(tabelle,iSpalten,target,target_pfad); abwicklung(tabelle,array,iSpalten); wait4key(); return 0; } }
Soo ... dass ist mein Quelltext ... ich zeige euch die datei aus der gelesen wird, und die in die geschrieben wurde.
Quelldatei:
2600312000 0.35
2600312001 0.35
2605411057 38048
2605430011 25569
2605438090 25.81
2607002195 34851
2607019164 25903
2607019165 25903
2607019166 25903
2607224908 29707
2608584743 317.43
2608584744 451.72
2608584745 310.69
2608584746 480.40
2608584747 277.50
2608584748 440.06
2608584749 396.74
2608597426 16834
2608597427 19756
2608597432 32568
2608597433 45748
2608600430 23043
2608607428 20090
2608607429 13150
2608607430 11324
2608607431 11324
2608607432 18264
2608633862 0.75
2608640540 18.13
2608640564 22.62
2608640570 28.82
2608640639 21337
2608640751 13.30
2608640767 11933
2608640771 51.04
2608640817 13850
2608640823 42675
2608690091 30042
2609251301 38139
2609251701 14977
2609251832 38232
2609251855 11383
2609251857 15432
2609252068 0.98
2609992773 38049
2609992775 34731
1619A00N08 0.2
1619A00N16 0.2
1619A00N17 0.2
1619A00N25 0.9
1619A00N33 0.9
1619A00N43 38139
1619A00N60 49.5
1619A00N62 49.5
1619A00N69 49.5
1619A00N78 38144
1619A00N87 38144
1619A00P04 0.2
1619A00P05 0.2
1619A00P07 0.2
1619A00P0A 49.5
1619A00P0C 49.5
1619A00P0D 38144
1619A00P0E 32
1619A00P0K 0.9
1619A00P1H 2
1619A00P1J 2
1619A00P1K 2
1619A00P1R 2
1619A00P1S 2
1619A00P1U 2
1619A00P20 2
1619A00P21 2
1619A00P27 3
1619A00P28 3
1619A00P29 3
1619A00P2E 3
1619A00P2F 3
1619A00P2H 3
1619A00P2K 3
1619A00P2P 3
1619A00P2Y 7
1619A00P31 7
1619A00P34 7
1619A00P35 7
1619A00P3E 7
1619A00P3M 0.25
1619A00P3N 0.25
1619A00P3U 0.25
1619A00P3V 0.25
1619A00P44 0.25
1619A00P51 45658
1619A00P52 45658
1619A00P54 45658
1619A00P57 45658
1619A00P58 45658
1619A00P5C 45658
1619A00P5H 45658
1619A00P74 45658
1619A00P75 45658
1619A00P7A 45658
1619A00P7B 45658
1619A00P7K 45658
1619A00P7L 45658
1619A00P7U 45658
1619A00P7V 45658
1619A00P7X 45658
1619A00P80 45658
1619A00P81 45658
1619A00P85 45658
1619A00P8A 45658
1619A00P9W 45658
1619A00P9X 45658
1619A00P9Y 45658
1619A00PA0 45658
1619A00PA3 45658
1619A00PA4 45658
1619A00PAD 45658
1619A00PBB 38139
1619A00PBT 38139
1619A00PCR 38139
1619A00PD6 38139
1619A00PDE 38139
1619A00PDW 38139
1619A00PFG 38139
1619A00PFH 38139
1619A00PFP 38139
1619A00PFZ 38139
1619A00PGR 12816
1619A00PGS 12816
1619A00PGV 12816
1619A00PGY 12816
1619A00PGZ 12816
1619A00PH1 12816
1619A00PH4 12816
1619A00PH5 12816
1619A00PH6 42036
1619A00PHA 42036
1619A00PHC 42036
1619A00PHD 42036
1619A00PHG 42036
1619A00PHL 42036
1619A00PHM 0.95
1619A00PHT 12816
1619A00PHY 42036
1619A00PJ3 0.2
1619A00PJ4 0.9Und hier das File dass dabei rauskommt:
2600312000 0.35
2600312001 0.35
2605411057 38048
2605430011 25569
2605438090 25.81
2607002195 34851
2607019164 25903
2607019165 25903
2607019166 25903
2607224908 29707
2608584743 317.43
2608584744 451.72
2608584745 310.69
2608584746 480.40
2608584747 277.50
2608584748 440.06
2608584749 396.74
2608597426 16834
2608597427 19756
2608597432 32568
2608597433 45748
2608600430 23043
2608607428 20090
2608607429 13150
2608607430 11324
2608607431 11324
2608607432 18264
2608633862 0.75
2608640540 18.13
2608640564 22.62
2608640570 28.82
2608640639 21337
2608640751 13.30
2608640767 11933
2608640771 51.04
2608640817 13850
2608640823 42675
2608690091 30042
2609251301 38139
2609251701 14977
2609251832 38232
2609251855 11383
2609251857 15432
2609252068 0.98
2609992773 38049
2609992775 34731
1619A00N08 0.2
1619A00N16 0.2
1619A00N17 0.2
1619A00N25 0.9
1619A00N33 0.9
1619A00N43 38139
1619A00N60 49.5
1619A00N62 49.5
1619A00N69 49.5
1619A00N78 38144
1619A00N87 38144
1619A00P04 0.2
1619A00P05 0.2
1619A00P07 0.2
1619A00P0A 49.5
1619A00P0C 49.5
1619A00P0D 38144
1619A00P0E 32
1619A00P0K 0.9
1619A00P1H 2
1619A00P1J 2
1619A00P1K 2
1619A00P1R 2
1619A00P1S 2
1619A00P1U 2
1619A00P20 2
1619A00P21 2
1619A00P27 3
1619A00P28 3
1619A00P29 3
1619A00P2E 3
1619A00P2F 3
1619A00P2H 3
1619A00P2K 3
1619A00P2P 3
1619A00P2Y 7
1619A00P31 7
1619A00P34 7
1619A00P35 7
1619A00P3E 7
1619A00P3M 0.25
1619A00P3N 0.25
1619A00P3U 0.25
1619A00P3V 0.25
1619A00P44 0.25
1619A00P51 45658
1619A00P52 45658
1619A00P54 45658
1619A00P57 45658
1619A00P58 45658
1619A00P5C 45658
1619A00P5H 45658
1619A00P74 45658
1619A00P75 45658
1619A00P7A 45658
1619A00P7B 45658
1619A00P7K 45658
1619A00P7L 45658
1619A00P7U 45658
1619A00P7V 45658
1619A00P7X 45658
1619A00P80 45658
1619A00P81 45658
1619A00P85 45658
1619A00P8A 45658
1619A00P9W 45658
1619A00P9X 45658
1619A00P9Y 45658
1619A00PA0 45658
1619A00PA3 45658
1619A00PA4 45658
1619A00PAD 45658
1619A00PBB 38139
1619A00PBT 38139
1619A00PCR 38139
1619A00PD6 38139
1619A00PDE 38139
1619A00PDW 38139
1619A00PFG 38139
1619A00PFH 38139
1619A00PFP 38139
1619A00PFZ 38139
1619A00PGR 12816
1619A00PGS 12816
1619A00PGV 12816
1619A00PGY 12816
1619A00PGZ 12816
1619A00PH1 12816
1619A00PH4 12816
1619A00PH5 12816
1619A00PH6 42036
1619A00PHA 42036
1619A00PHC 42036
1619A00PHD 42036
1619A00PHG 42036
1619A00PHL 42036
1619A00PHM 0.95
1619A00PHT 12816
1619A00PHY 42036
1619A00PJ3 0.2
1619A00PJ4 0.9Soo ... und mein Problem ist, dass der am Ende diese komischen Zeichen anhängt. die Dürfen aber nicht sein, weil am ende dass alles in einen Automatisierungsprozess eingebunden wird ... könnt Ihr mir helfen woran des liegen könnte ???
-
Versuche es mal anderst zu lösen ... mit nem struct array ... ist praktischer, glaube ich
-
wo sind bitte die Unterschiede?
Habe die beiden Dateien verglichen sie sind identisch??
-
Eben nicht! des ist mein Problem ... schau dir mal die letzte Zeile an. Da siehst du, dass der am Ende noch was dranhängt. Und ich weiss nicht warum.
-
Also habe mein Problem gelöst. Habe das ganze Programm umstrukturiert und wie folgt die Tabelle eingelesen:
struct sTabelle { char var1[11]; //Erster Wert char var2[11]; //Zweiter Wert char zeile[100]; //zur Weiterverarbeitung nötig } ; ... ... ... void write_table(struct sTabelle tabelle[MAX_ZEILEN],char array[ZEICHEN]){ int a; int index=0; int zeilen=0; int c=0; int b=0; /* Zeilenweise einlesen der Tabelle */ for(a=0;array[a]!='\0';a++){ tabelle[zeilen].zeile[c]=array[a]; printf("%c",tabelle[zeilen].zeile[c]); c++; if (array[a]=='\n'){ zeilen++; c=0; } } b=0; /* aufschlüsseln der jeweiligen Zeilen auf die gesuchten Informationen */ for(a=0;a!=zeilen;a++){ c=0; tabelle[a].var2[0]='\0'; tabelle[a].var1[0]='\0'; for(b=0;c<10;b++){ tabelle[a].var2[b]=tabelle[a].zeile[c]; c++; } for(b=0;c>=10 && c<19;b++){ if (tabelle[a].zeile[c]=='\t') // Überspringen des Tabulators damit er nicht kopiert wird c++; tabelle[a].var1[b]=tabelle[a].zeile[c]; c++; } } }
Also fals es jemanden interessiert ... so läuft des jetzt ...