Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "header.h"
- int main(int argc, char *argv[]) {
- int anz=0;
- char textZeile[300];
- FILE *fp = fopen("Handydatei.csv","rt");
- handy_t *hilfe;
- if(!fp) {
- puts("Datei wurde nicht gefunden!");
- return 1;
- }
- while(fgets(textZeile,sizeof(textZeile),fp)) {
- if(!erzeugeHandy(hilfe,textZeile)){
- anz++;
- }
- }
- handy_t *handys = calloc(anz,sizeof(handy_t));
- return 0;
- }
- #include "header.h"
- int erzeugeHandy(handy_t *handy, char *textZeile){
- char kopie[strlen(textZeile)+1];
- char *token;
- char dummy;
- int ok;
- int speicher;
- double preis;
- strcpy(kopie,textZeile);
- token = strtok(kopie,";");
- if(gueltigeImeiNummer(token,strlen(token))){
- return 1;
- }
- strcpy(handy->imeiNummer,token);
- token = strtok(NULL,";");
- strcpy(handy->bezeichnung,token);
- token = strtok(NULL,";");
- ok = sscanf(token,"%d%c",&speicher,&dummy);
- if(speicher < 0 || ok != 1){
- return 1;
- }
- token = strtok(NULL,"\\s");
- ok = sscanf(token,"%lf%c",&preis,&dummy);
- if(preis < 0.0 || ok != 1){
- return 1;
- }
- handy->preis = preis;
- return 0;
- }
- int gueltigeImeiNummer(char *text, size_t n){
- size_t i;
- if(n <15 || n > 19){
- return 1;
- }
- for(i=0;i<n;i++){
- if(!isdigit(text[i])){
- return 1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement