Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <iostream>
- #include <time.h>
- #include <fstream>
- #define W 800
- #define H 600
- #define OFF 10
- #include <cmath>
- using namespace std;
- int* generuj(int ile)
- {
- int* tmp;
- srand(time(NULL));
- int i;
- if (ile < 1)
- return 0;
- tmp = new int[ile];
- for(i=0;i<ile;++i)
- tmp[i]=rand()%10;
- return tmp;
- }
- int liczR(char name[]){
- ifstream p;
- string tmp;
- int i=0;
- p.open(name);
- while(p.good())
- {
- getline(p,tmp);
- i++;
- }
- p.close();
- return i;
- }
- int liczC(char name[]){
- ifstream p;
- char c;
- int i=0,tmp;
- p.open(name);
- while(p.good())
- {
- p >> tmp;
- p.get(c);
- i++;
- if(c=='\n')break;
- }
- p.close();
- return i;
- }
- int** generuj(int R, int C){
- int **tmp;
- tmp = new int *[R];
- for (int i = 0; i < R; i++)
- tmp[i] = new int [C];
- return tmp;
- }
- int** czytaj(char name[],int*R,int*C){
- int** tmp;
- ifstream p;
- *R=liczR(name);
- *C=liczC(name);
- tmp=generuj(*R,*C);
- p.open(name);
- for(int i=0;i<*R;i++){
- for(int j=0;j<*C;j++){
- p>>tmp[i][j];
- p.get();//przeskakuje o jeden zank
- }
- }
- p.close();
- return tmp;
- }
- int main()
- {
- int *tab1;
- int j=0;
- int N=10;
- tab1 = generuj(N);
- for (j=0; j<N; j++)
- cout<< tab1[j] << " "<< endl;
- return 0;
- int **tab, R,C;
- char fileO[]={"linia.csv"};
- tab = czytaj(fileO,&R,&C);
- for(int i=0;i<R;i++){
- for(int j=0;j<C;j++){
- cout<<tab[i][j]<<";";
- }
- cout<<endl;
- }
- int xx[]={OFF,OFF,W-OFF,W-OFF,OFF};
- int yy[]={OFF,H-OFF,H-OFF,OFF,OFF};
- int i;
- sf::VertexArray linie(sf::Lines);
- for(i=0;i<4;i++){
- linie.append(sf::Vector2f(xx[i],yy[i]));
- linie.append(sf::Vector2f(xx[i+1],yy[i+1]));
- }
- ;
- // Create the main window
- sf::RenderWindow window(sf::VideoMode(W,H), "SFML window");
- // Start the game loop
- while (window.isOpen())
- {
- // Process events
- sf::Event event;
- while (window.pollEvent(event))
- {
- // Close window : exit
- if (event.type == sf::Event::Closed)
- window.close();
- }
- // Clear screen
- window.clear();
- window.draw(linie);
- // Update the window
- window.display();
- }
- return EXIT_SUCCESS;;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement