0

First Post, will do my best to follow guidelines and make this a proper setup. If ANYTHING is needed, let me know!

The error in VS 2019 is "C6064: Missing integer argument to 'fscanf' that corresponds to conversion specificer '2'." The code below is given in the part where my code breaks. The rest up to this point is fine and compiles correctly. The line in error is the fscanf.

ENTIRE CODE: https://pastebin.com/DCgEa64g (Excuse any missing variables, they have been dealt with!)

fp = fopen("codefile.txt", "r");
if (fp == NULL)
{
    printf("could not open codefile.txt\n");
    return 1;
}

i = 0;
while (!feof(fp))
{

    fscanf(fp, "%c", &code[i]);
    i++;
}

This portion I posted is me scanning a file, codefile.txt, and saving each character inside to a string array, then comparing that array to a "ciphered message" to get an answer. The code compiles the correct answer, but I can't get this error to go away. The other message present is "'fscanf': not enough arguments passed for the format string" but I assumed only %c was needed for a character in a string array?

This also puts each element in codefile.txt into the code array individually, which IS intended. I finished the rest of this assignment, so I'm not asking for somebody to do anything else at all for me. I will gladly post any other code needed! The goal is to read in a separate message file with numbers, put them into an array, descramble and compare to the codefile.txt string and get the result. I did 95% of the work, and need some help! Any clarification, just ask! Turning this in tomorrow evening :)

Aaron Jackson
  • 13
  • 1
  • 4
  • Welcome to Stack Overflow. Please take the time to go through the [The Tour](http://stackoverflow.com/tour) and refer to the material from the [Help Center](http://stackoverflow.com/help/asking) on what and how you can ask here.It's specially important to post a [mcve]. – R Sahu Nov 17 '19 at 04:02
  • Alright! I will edit in a few minutes, getting a less messy version now! – Aaron Jackson Nov 17 '19 at 04:06

2 Answers2

1

Your actual code (at the link, not in your question) uses fscanf_s(), whose documentation says:

The main difference between the more secure functions (that have the _s suffix) and the other versions is that the more secure functions require the size in characters of each c, C, s, S, and [ type field to be passed as an argument immediately following the variable. For more information, see scanf_s, _scanf_s_l, wscanf_s, _wscanf_s_l and scanf Width Specification.

Your error is in failing to provide the additional size argument.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • Alright, I have an idea of what you're getting at. What would that look like implemented? I can't figure where i'd put SIZE inside this statement, and eventually turned to CRT_SECURE_NO_WARNINGS for other errors but this still pops up. Any hint? – Aaron Jackson Nov 17 '19 at 04:25
1

Thank You John Zwinck; I eventually got it working through adding SIZE to the argument when using fscanf_s specifically. Answer looks like this:

    while (!feof(fp))
{
    fscanf_s(fp, "%c", &code[i], SIZE); //SIZE was added here!
    i++;
}

Thanks for the help!

Aaron Jackson
  • 13
  • 1
  • 4