Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int isNumber(string thing){
- for(int i=0; i<thing.length(); i++){
- if( thing[i]!=45 && (thing[i]<48 || thing[i]>57))
- return 0;
- }
- return 1;
- }
- int checkFile(){
- string nr;
- if(!file.good()){
- cout<<"Brak pliku data.txt"<<endl;
- return 0;
- }
- for(int i=0; true; i++){
- file >> nr;
- //fscanf(file, "%s\n", &nr);
- //printf("%d %s ", i+1, nr);
- //cout<<nr<<" : "<<isNumber(nr)<<endl;
- if(file.eof()){
- //cout<<"h"<<endl;
- return i;
- }
- if(!isNumber(nr)){
- //cout<<nr<<endl;
- return 0;
- }
- }
- }
- void loadFile(int tab[]){
- int fileSize=checkFile();
- //cout<<fileSize<<endl;
- if(fileSize){
- //fclose(file);
- fstream f;
- f.open("data.txt");
- for(int i=0; i<arraySize; i++){
- f >> tab[i];
- //fscanf(f, "%d\n", &numbers[i]);
- }
- //fclose(f);
- }else{
- error++;
- cout<<"dane nieprawidlowe"<<endl;
- }
- }
- void keyboard(int tab[]){
- for (int i = 0; i < arraySize; i++) {
- string z;
- cin>>z;
- if (isNumber(z)==1){
- stringstream geek(z);
- int x ;
- geek >> x;
- tab[i]=x;
- }else{
- error++;
- printf("Niepoprawna wartosc wprowadzona");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement