0

I'm working on a code with the goal of reading a file that has list of random number combinations and random character combinations separated by a space.

eg

0016718719  #:@-;QZL=!9v
0140100781  &:`ziuiCM+UC

...and so on

I would like to read them into a binary search tree using the number as a key and the character combination as a linked piece of data. The number would represent something like an employee ID number and the character combination a password. I want to use an integer to store the numbers and a pointer to a string to store the characters in a while loop to transfer them into the tree.

test code to open the file

I have been trying to figure out the fscanf tool on a small scale program so far. The output of the program is the error accessing file message.

Any help is very much appreciated. I cannot figure out why the file won't open.

user3386109
  • 34,287
  • 7
  • 49
  • 68
  • 3
    The code should be copy/pasted into the question itself. See [mcve]. – user3386109 Oct 20 '20 at 03:01
  • 1
    When the `fopen` fails call `perror` to get a more exact error msg. Also, are you sure that file exists and has the right permissions? – kaylum Oct 20 '20 at 03:09
  • There are N number of sources , refer [link](https://www.google.com/search?q=fscanf+example+in+c&rlz=1C1GCEB_enIN902IN903&oq=fscanf+example+in+c&aqs=chrome..69i57j0l6j69i60.551j0j7&sourceid=chrome&ie=UTF-8) – IrAM Oct 20 '20 at 03:12
  • 1
    Actually, why are you asking about the `fscanf` when it seems like you are saying the `fopen` has an error? Which means it never gets to the `fscanf`. Please clarify. – kaylum Oct 20 '20 at 03:14
  • The "id" might not fit in an `int`. And the leading zeros will be lost if using numeric types (if they are signifikant). I recommend using strings for both elements. – Some programmer dude Oct 20 '20 at 03:16
  • 1
    I also recommend using `fgets` to read full lines, and then possibly `sscanf` for parsing. And remember to check what `fscanf`/`sscanf` actually returns (it should return `2`). – Some programmer dude Oct 20 '20 at 03:17
  • https://stackoverflow.com/questions/5431941/why-is-while-feof-file-always-wrong AND you have an extremely suspicious `;` in that vicinity. So suspicious that I doubt you can even compile it, let alone run... And please do not show pictures of text. Make a MRE right here. please. – Yunnosch Oct 20 '20 at 06:12

0 Answers0