Advertisement
Guest User

dfd

a guest
Dec 21st, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. int** getArray(int &r, int &c)
  2. {
  3. string st;
  4. char s[50];
  5. int** arResult;
  6. int* bufRow;
  7. int buf, k, j, y, x=2;
  8. unsigned int rows, columns;
  9. ifstream input("in.txt", ios::in);
  10.  
  11. if (input.bad())
  12. return NULL;
  13.  
  14.  
  15. input >> rows;
  16. input >> columns;
  17.  
  18. input.close();
  19.  
  20. if (input.eof())
  21. return NULL;
  22. arResult = new int*[rows];
  23. for (int i = 0; i < rows; i++)
  24. {
  25. ifstream input("in.txt", ios::in);
  26.  
  27. for(y=0;y<x;y++)
  28. getline (input,st);
  29. bufRow = new int[columns];
  30. k=0;
  31. cout << st.length()<< endl << endl;;
  32. for(j=0; j< st.length(); j++)
  33. {
  34. s[k]=st[j];
  35. cout << s[k];
  36. if(isdigit(s[k]))
  37. {
  38. k++;
  39. }
  40. input >> s[k];
  41.  
  42. }
  43. cout << endl;
  44. for (j = 0; j < columns; j++)
  45. {
  46.  
  47. if (!(isdigit(s[j])))
  48. {
  49. bufRow = NULL;
  50. }
  51. else
  52. {
  53. bufRow[j] = s[j]-'0';
  54. }
  55.  
  56. }
  57.  
  58. if (bufRow == NULL)
  59. {
  60. rows = i;
  61. break;
  62. }
  63.  
  64. arResult[i] = bufRow;
  65. x++;
  66. input.close();
  67. }
  68.  
  69. r = rows;
  70. c = columns;
  71. return arResult;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement