Read in a text-file

Hello,
I use MS-VisualStudio 2015.
I want to read in a text-file to bring it out with another format.
But there is no text at the screen?
Here is the code:

//---------------------------------------------------------------------------

#include<stdio.h>
#include<stdlib.h>
#include<share.h>
#include"stdafx.h"

int main(void)
{
FILE *stream
char s[12];
char c;
if (fopen_s(&stream, "NetWorkNeu1.txt", "r") != 0)
printf("The file fscanf.out was not opened\n");
else
{
fscanf_s(stream, "%c", &c);
fscanf_s(stream, "%s", s);

printf("%s\n", s);
printf("%c\n", c);

fprintf_s(stream,"%s\n", s);
fprintf_s(stream,"%c\n", &c);

fclose(stream);
}
return 0;
}

This is a C++ forum, not C forum.
You can use ifstream to replace fopen_s, fscanf_s.

1
2
fprintf_s(stream,"%s\n", s);
fprintf_s(stream,"%c\n", &c);

You are opening the file with "read" attribute. Of course you can't use this function f_printf_s.
Try this to see an error msg:
1
2
if (fopen_s(&stream, "NetWorkNeu1.txt", "r") != 0)
   perror("Error reading file: ");
Here I get the message:

Error reading file:: No error
Your condition is wrong. fopen_s(&stream, "NetWorkNeu1.txt", "r") != 0 A return code != 0 means everything is ok. As Fanboro mentioned if you open the file for reading you should not try to write into it.
....yes....you are right, I had to put the write-order after the close-funktion...!

...be sure, the next problem comes soon...

Thank you
Topic archived. No new replies allowed.