Thread: Read in a text-file

  1. #1
    Registered User
    Join Date
    Nov 2016
    Posts
    2

    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:

    insert
    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;
    }

  2. #2
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528

    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.

    -- MSDN

    You don't have such in your code.

  3. #3
    Registered User
    Join Date
    Nov 2016
    Posts
    2
    ....would you please give me an example?

  4. #4
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by Kalle2020 View Post
    ....would you please give me an example?
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<share.h>
    #include"stdafx.h"
    
    int main(void)
    {
        FILE *stream
        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, 1); //read one character
    
            printf(" %c", c);
    
    
            fclose(stream);
        }
    
        return 0;
    }
    There you go.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File processing: How to read a part of a text file?
    By HardOverdrive in forum C Programming
    Replies: 4
    Last Post: 12-05-2011, 12:33 PM
  2. read from text file help!!
    By student2007 in forum C++ Programming
    Replies: 5
    Last Post: 12-05-2007, 02:58 AM
  3. How to Read Text file in C !!
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 07-17-2002, 07:53 AM
  4. Read a Text File
    By c++ newone in forum C++ Programming
    Replies: 1
    Last Post: 11-15-2001, 05:27 PM

Tags for this Thread