I have my function dumpArray(); which does this:
void dumpArray(void)
{
while(p <= i)
{
printf("%i:", packet[p].source);
printf("%i:", packet[p].dest);
printf("%i:", packet[p].type);
printf("%i\n", packet[p].port);
p++;
}
}
And I’m trying to pass this into a fprintf(); as such:
void fWrite(void)
{
char fileName[30] = { '\0' };
printf("Please specify a filename: ");
scanf("%s", fileName) ;
FILE *txtFile;
txtFile = fopen(fileName, "w");
if (txtFile == NULL)
{
printf("Can't open file!");
exit(1);
}
else fprintf(txtFile, dumpArray());
}
I’m trying to write the result of dumpArray(); into the file.
Could anyone see where I’m going wrong and point me in the right direction.
You could rewrite dumparray to either write to stdout or to your textfile depending which stream you pass in.
So you would change all of your printf calls to fprintf and pass the stream as the first argument.