Can we a read a particular line(any line, not from the start or not continuously from a line to the end of the file) at a file using fscanf? I want to discard lines other than that particular line.
I recommend to just read each line it is, and then check each line until you find the one you want, unless of course as the poster above states, you know how many lines it is in then just fgets until you have reached the required line, but this is not a very good method imo.
while not end of file
if line is not correct then discard elsedo some processing on this line
It's printing "player_no" value.i.e if contrycode =1 & btnid =1,it will print 11 Not the contents of row corresponting to 11of myfile.I want the contents of the row of myfile corresponting to player_no to be printed.
How to do?
I'm not sure what you're trying to do but if you only want a single row don't read the entire file. If you want player N (and you're using zero based indexing) read and discard the first N and read the (N + 1)th into the string.
Another option is to fix the size of the fields in the file so you can seek to the start of a particular line before doing a read.
Yet another is to create a class that represents each line (presumably player) and implement a constructor that initialises itself from a stream or an overloaded extraction operator.
There's a getline[^] which accepts std::strings. Have you added #include <string> to the include files? If you haven't added using namespace std; somewhere in the scope remember you need to use a fully qualified name: std::string.