Ahoj, mám menší problém s tímto kódem:
void ReadFromFile(TDatabase *database)
{
FILE *Database;
Database = fopen(FILENAME, "a+"); //čtení Database.
TDatabase *Actually = (TDatabase*)malloc(sizeof(TDatabase));
char *p, *token;
int inc = 0;
char *Line = (char*)malloc(sizeof(char));
while(NULL != fgets(Line, sizeof(Line), Database))
{
if ((p = strrchr(Line, '\n')) != NULL) *p = '�';
token = strtok(Line, ';');
while (token != NULL) {
switch(inc)
{
case 0: Actually->ID = atoi(token); break;
case 1: Actually->SPZ = token; break;
case 2: Actually->Name = token; break;
case 3: Actually->Surname = token; break;
case 4: Actually->INplace = token; break;
case 5: Actually->INdate = token; break;
case 6: Actually->INtime = token; break;
case 7: Actually->OUTplace = token; break;
case 8: Actually->OUTdate = token; break;
case 9: Actually->OUTtime = token; break;
case 10: Actually->distance = atoi(token); break;
case 11: Actually->fuelconsumption = atoi(token); break;
default : printf("Error: Chyba v databazi!"); break;
}
inc++;
token = strtok(NULL, ';');
AddEnd(&database, Actually->ID, Actually->SPZ, Actually->Name, Actually->Surname, Actually->INplace, Actually->INdate, Actually->INtime,
Actually->OUTplace, Actually->OUTdate, Actually->OUTtime, Actually->distance, Actually->fuelconsumption);
}
inc = 0;
Line = NULL;
Line = (char*)malloc(sizeof(char));
}
}
/*//rewind(Database);
bool Vysledek;
do
{
TDatabase *Actually = (TDatabase*)malloc(sizeof(TDatabase));
Vysledek = fscanf(Database, "%d;%s;%s;%s;%s;%s;%s;%s;%s;%s;%d;%.2f\n", &Actually->ID, Actually->SPZ, Actually->Name, Actually->Surname, Actually->INplace,
Actually->INdate, Actually->INtime, Actually->OUTplace, Actually->OUTdate, Actually->OUTtime, &Actually->distance, &Actually->fuelconsumption) == 1;
AddEnd(&database,Actually->ID, Actually->SPZ, Actually->Name, Actually->Surname, Actually->INplace,
Actually->INdate, Actually->INtime, Actually->OUTplace, Actually->OUTdate, Actually->OUTtime, Actually->distance, Actually->fuelconsumption);
Actually = NULL;
} while(Vysledek);
fclose(Database);
}
*/
hlásí mi to tyto chyby u všech položek ve switch a token = strtok(xxxx);
Error 22 error C2440: '=' : cannot convert from 'char *' to 'char [10]'
'strtok' : cannot convert parameter 2 from 'char' to 'const char *'
Lineární pole:
struct TDatabase {
int ID;
char SPZ[10];
char Name[20];
char Surname[20];
char INplace[20];
char INdate[10];
char INtime[5];
char OUTplace[20];
char OUTdate[10];
char OUTtime[5];
int distance;
float fuelconsumption;
TDatabase *Next;
};
Děkuji předem za pomoc s vyřešením tohoto problému.
edit.: nebo mám předělat položky lineárního pole na dynamické?