Try to debug this code, fscanf_s does not read from an input text file
numbers.txt that has 20 integers separated by a space. What I am doing
wrong ??
#include <stdio.h>
#include "stdafx.h"
#include <stdlib.h>
#define SIZE 20 /* size of elements in the the sequence of numbers */
int _tmain(int argc, _TCHAR* argv[])
{
int array[SIZE];
int i, pass, hold;
FILE *fp;
/* opens the file in in read only mode */
if(fopen_s(&fp,"d:\\numbers.txt","r")!=0)
{
printf("Error opening the file\n");
exit(1);
}
/* load the data in the array */
else
{
for(i=0;i<=SIZE-1;i++)
{
fscanf_s(fp,"%d",&array[i]);
}
}
fclose(fp);
/* show data */
for(i=0;i<=SIZE-1;i++)
{
printf("%d ", array[i]);
}
printf("\n");
return 0;
}