Advertisement
Guest User

Wstep

a guest
Apr 6th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. int isNumber(string thing){
  2.     for(int i=0; i<thing.length(); i++){
  3.         if( thing[i]!=45 &&  (thing[i]<48 || thing[i]>57))
  4.             return 0;
  5.     }
  6.     return 1;
  7. }
  8.  
  9. int checkFile(){
  10.     string nr;
  11.     if(!file.good()){
  12.         cout<<"Brak pliku data.txt"<<endl;
  13.         return 0;
  14.     }
  15.  
  16.     for(int i=0; true; i++){
  17.         file >> nr;
  18.         //fscanf(file, "%s\n", &nr);
  19.         //printf("%d %s ", i+1, nr);
  20.  
  21.         //cout<<nr<<" : "<<isNumber(nr)<<endl;
  22.         if(file.eof()){
  23.             //cout<<"h"<<endl;
  24.             return i;
  25.         }
  26.  
  27.         if(!isNumber(nr)){
  28.             //cout<<nr<<endl;
  29.             return 0;
  30.         }
  31.     }
  32. }
  33.  
  34. void loadFile(int tab[]){
  35.     int fileSize=checkFile();
  36.     //cout<<fileSize<<endl;
  37.     if(fileSize){
  38.         //fclose(file);
  39.         fstream f;
  40.         f.open("data.txt");
  41.         for(int i=0; i<arraySize; i++){
  42.             f >> tab[i];
  43.             //fscanf(f, "%d\n", &numbers[i]);
  44.         }
  45.         //fclose(f);
  46.     }else{
  47.         error++;
  48.         cout<<"dane nieprawidlowe"<<endl;
  49.     }
  50. }
  51.  
  52. void keyboard(int tab[]){
  53.     for (int i = 0; i < arraySize; i++) {
  54.         string z;
  55.         cin>>z;
  56.         if (isNumber(z)==1){
  57.             stringstream geek(z);
  58.             int x ;
  59.             geek >> x;
  60.             tab[i]=x;
  61.         }else{
  62.             error++;
  63.             printf("Niepoprawna wartosc wprowadzona");
  64.             break;
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement