Advertisement
nick43ui

Untitled

Apr 27th, 2020
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7. string str1 = "File_data.txt";
  8.  
  9. void check_real_number();
  10.  
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14. int index = 0;
  15. char *buffer = new char[1024];
  16.  
  17. cout <<"Enter number, real number, and words by space:" << endl;
  18. cin.get(buffer[index]);
  19. while (buffer[index] != '\n')
  20. {
  21. ++index;
  22. cin.get(buffer[index]);
  23. }
  24. buffer[index] = '\0'; // нужен чтобы знать где заканчивается строка
  25.  
  26. // запис даних у файл
  27. ofstream filename1;
  28. filename1.open(str1,std::ios_base::out | std::ios_base::trunc);
  29. filename1 << buffer;
  30. filename1.close();
  31. delete[] buffer;
  32. check_real_number();
  33.  
  34. //sort_real_number();
  35.  
  36. return 0;
  37. }
  38.  
  39. void check_real_number() //Проверка или в файле есть действительные числаn
  40. {
  41.  
  42. int n = 0;
  43. ifstream filename2;
  44. filename2.open(str1);
  45. if(!filename2.is_open())
  46. cerr << "Error, file is not open!" << endl;
  47. else
  48. {
  49. cout << "File is open!\n" << endl;
  50. string ch;
  51. while(!filename2.eof())
  52. {
  53. getline(filename2,ch);
  54. //cout << ch;
  55. }
  56. cout << endl;
  57.  
  58. for (int i = 0; i < ch.length(); ++i)
  59. {
  60. if(ch[i] == '.' && int(ch[i-1]) >= '0' && int(ch[i+1] <= '9'))
  61. {
  62. if(ch[i] == '.' && ch[i+1] == '.')
  63. continue;
  64. ++n;
  65. }
  66. }
  67. cout << "There are real number: " << n <<endl;
  68. }
  69.  
  70. cout << endl;
  71. filename2.close();
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement