Task: Read the file line by line, the string is written in the character buffer. Each character is compared with the "correct" (I, J) character, after the character there is a number that is written into a variable divided by 1000 and displayed on the screen. Garbage symbols: F, R, H, Q and other slag is skipped.
I tried to nakodit, it turned out to bring only the numbers from the first line many, many times, and then nothing = (I’m getting my head on the table. I don’t understand what’s wrong. Please tell me who’s interested =)
Sample input file.
In it randomly there are different letters and numbers randomly.
N10I-255961J-829096F-360873 N11I-254238F-360873 N12J931921 N13Y-251413H-332067 N14I-653588 N15I248588F-332245 N16Q251413J-332085H-332067 N17I252145J331921 ..................... ..................... ..................... и так далее......... и так далее.........
My code.
#include <fstream> #include <iostream> #include <ctype.h> #include <sstream> #include <stdio.h> int main() { int k=0; FILE *ifs = fopen("input.txt", "rt"); std::stringstream i,j; float i1=0,j1=0; char buf[1024]; while(fgets(buf,1024,ifs)){ while(buf[k]){ if (isalpha(buf[k])){ if ((int)buf[k]==73 && ((int)buf[k+1] > 44 && (int)buf[k+1] < 58)){//I do {i<<buf[k+1]; k++;} while (!isalpha(buf[k+1])); i>>i1; } if ((int)buf[k]==74 && ((int)buf[k+1] > 44 && (int)buf[k+1] < 58)){//J do {j<<buf[k+1]; k++;} while (!isalpha(buf[k+1])); j>>j1; } } else if (isdigit(buf[k])){ } k++;} std::cout <<"i" <<i1/1000<<std::endl; std::cout <<"j" <<i1/1000<<std::endl; } system("pause"); } Must be displayed
i-255.961 j-829.096 j931.921 i-653.588 i248.588 i252.145 j331.921
CorC++. 3) Formulate the problem more precisely: print the number that immediately follows the charactersIorJ, skip the rest. The mark is taken into account. So? - PinkTuxc++). 3 Yes, print the number after the charactersIandJ, skip the rest. Above is an example of how it should look. The mark is taken into account. =) - IronZeshadowc++you can use theclanguage, but not vice versa, set it if I am mistaken =) - IronZeshadowawk... But the code in the answer will be assembled as you like, both purely and positively. - PinkTux