Habe gerade zur Übung ein Programm geschrieben, aber es funktioniert einfach nicht. Ich mache immer den selben Fehler, weiß aber nicht welchen und warum.
Bitte um Hifle

Code: Alles auswählen
/*
* File: main.c
* Author: Marcel
*
* Created on 2. November 2014, 10:35
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
*
*/
struct Cd
{
char titel[31];
int jahr;
double dauer;
};
int leseCDs(struct Cd feld[], int max , FILE *f)
{
struct Cd cd;
char s[1000];
int n;
int i;
if (f == NULL)
{
fclose(f);
return-2;
}
for(i=0; i>-1; i++)
{
char s[1000];
char *p;
if (fgets(s, sizeof(s), f) == NULL)
{
fclose(f);
return i;
}
p=strtok(s, ",");
if(p == NULL)
{
fclose(f);
return -3;
}
strncpy(cd.titel, p,sizeof cd.titel);
p=strtok(NULL, ",");
if(p == NULL)
{
fclose(f);
return -4;
}
n=sscanf(s, "%d", &cd.jahr) ;
if(n==0)
{
fclose(f);
return -5;
}
p=strtok(NULL, ",");
if(p == NULL)
{
fclose(f);
return -6;
}
n=sscanf(s, "%lf", &cd.dauer) ;
if(n==0)
{
fclose(f);
return -7;
}
feld[i] = cd;
}
}
struct Cd eingabeCD()
{
char s[100];
int n;
struct Cd cd;
do
{
printf("Titel eingeben: ");
fgets(s, sizeof(s), stdin);
}
while (s[0] == '\n');
strncpy(cd.titel, s, sizeof(cd.titel));
do
{
printf("Jahr eingeben: ");
fgets(s, sizeof(s), stdin);
n=sscanf(s, "%d", &cd.jahr );
}
while (n!=1 || cd.jahr<1900);
do
{
printf("Dauer eingeben: ");
fgets(s, sizeof(s), stdin);
n=sscanf(s, "%lf", &cd.dauer );
}
while (n!=1 || cd.dauer <0.0 || cd.dauer>100);
}
void ausgabe (struct Cd cd , int i)
{
printf("\nCD %d:\n", i);
printf("Titel: %s\n", cd.titel);
printf("Jahr: %d\n", cd.jahr);
printf("Dauer: %.2lf\n",cd.dauer);
printf("\n\n");
}
int main(int argc, char** argv)
{
struct Cd bibliothek[100];
int i;
int anzahl;
int err;
printf("\tListe der CD`s\n");
printf("\t--------------\n\n");
anzahl=leseCDs("daten.csv", bibliothek, 100);
if (anzahl<=0)
{
printf("Fehler beim Lesen der Datei %d\n\n",anzahl);
return -1;
}
for (i=0;i<anzahl;i++)
ausgabe(bibliothek[i], i+1);
bibliothek[anzahl]=eingabeCD(); //sovíele eingaben man machen will, soviele brauche ich
err=ausgabe("daten.csv", bibliothek, anzahl);
for (i=0;i<=anzahl;i++)
ausgabe(bibliothek[i], i+1);
return (EXIT_SUCCESS);
}
main.c:139:4: warning: passing argument 1 of 'leseCDs' from incompatible pointer type [enabled by default]
main.c:23:5: note: expected 'struct Cd *' but argument is of type 'char *'
main.c:139:4: warning: passing argument 2 of 'leseCDs' makes integer from pointer without a cast [enabled by default]
main.c:23:5: note: expected 'int' but argument is of type 'struct Cd *'
main.c:139:4: warning: passing argument 3 of 'leseCDs' makes pointer from integer without a cast [enabled by default]
main.c:23:5: note: expected 'struct FILE *' but argument is of type 'int'
main.c:156:5: error: incompatible type for argument 1 of 'ausgabe'
main.c:118:6: note: expected 'struct Cd' but argument is of type 'char *'
main.c:156:5: warning: passing argument 2 of 'ausgabe' makes integer from pointer without a cast [enabled by default]
main.c:118:6: note: expected 'int' but argument is of type 'struct Cd *'
main.c:156:5: error: too many arguments to function 'ausgabe'
main.c:118:6: note: declared here
main.c:156:8: error: void value not ignored as it ought to be
lg