Help for newbie please


N

Niv (KP)

I've downloaded Visual C++ from MicroSoft to start learing some some
simple 'C', particularly file I/O.

I copied this programme for "Teach yourself C...." but I'm getting
these warnings, although the prog does run.


///////////////////////////////////////////////////////////start of
prog
#include <stdio.h>

enum {SUCCESS, FAIL};

void CharReadWrite(FILE *fin, FILE *fout);

int main(void)
{
FILE *fptr1, *fptr2;
char fname1[]= "c:/vcpp/data_bytes.txt";
char fname2[]= "c:/vcpp/outp_bytes.txt";
int worked = SUCCESS;


if ((fptr1 = fopen(fname1, "r")) == NULL){
printf("Cannot open read file!");
worked = FAIL;
} else if ((fptr2 = fopen(fname2, "w")) == NULL){
printf("Cannot open write file!");
worked = FAIL;
} else {
CharReadWrite(fptr1, fptr2);
fclose(fptr1);
fclose(fptr2);
}
return worked;
}

// Function definition:
void CharReadWrite(FILE *fin, FILE *fout)
{
int c;

while ((c=fgetc(fin)) != EOF){
fputc(c,fout); // Write char to out-file.
putchar(c);
}
}


///////////////////////////end of prog.


Error messages are;

------ Build started: Project: file_read, Configuration: Debug Win32
------
Compiling...
cl : Command line warning D9035 : option 'Wp64' has been deprecated
and will be removed in a future release
file_read.cpp
c:\documents and settings\niv\my documents\visual studio 2008\projects
\file_read\file_read.cpp(15) : warning C4996: 'fopen': This function
or variable may be unsafe. Consider using fopen_s instead. To disable
deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h
(237) : see declaration of 'fopen'
c:\documents and settings\niv\my documents\visual studio 2008\projects
\file_read\file_read.cpp(18) : warning C4996: 'fopen': This function
or variable may be unsafe. Consider using fopen_s instead. To disable
deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h
(237) : see declaration of 'fopen'
c:\documents and settings\niv\my documents\visual studio 2008\projects
\file_read\file_read.cpp(32) : warning C4101: 'i' : unreferenced local
variable
Compiling manifest to resources...
Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
Copyright (C) Microsoft Corporation. All rights reserved.
Linking...
Embedding manifest...
Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
Copyright (C) Microsoft Corporation. All rights reserved.
Build log was saved at "file://c:\Documents and Settings\Niv\My
Documents\Visual Studio 2008\projects\file_read\Debug\BuildLog.htm"
file_read - 0 error(s), 4 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped
==========

Can someone tell me what to do to get rid of these warnings please?

I dabbled in C years ago, but the modern compilers seem to do a lot
more (like confuse!).
 
Ad

Advertisements

B

Ben Pfaff

Niv (KP) said:
c:\documents and settings\niv\my documents\visual studio 2008\projects
\file_read\file_read.cpp(15) : warning C4996: 'fopen': This function
or variable may be unsafe. Consider using fopen_s instead. To disable
deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h
(237) : see declaration of 'fopen'
c:\documents and settings\niv\my documents\visual studio 2008\projects
\file_read\file_read.cpp(18) : warning C4996: 'fopen': This function
or variable may be unsafe. Consider using fopen_s instead. To disable
deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h
(237) : see declaration of 'fopen'

You can ignore these warnings. They claim that you should use
non-standard C extensions instead of perfectly good standard C
functions. I don't recommend doing that.
c:\documents and settings\niv\my documents\visual studio 2008\projects
\file_read\file_read.cpp(32) : warning C4101: 'i' : unreferenced local
variable

This warning shows that you didn't actually post the code that
you compiled, since the code you compiled doesn't contain a
variable named 'i'.
 
Ad

Advertisements

P

Psi

I've downloaded Visual C++ from MicroSoft to start learing some some
simple 'C', particularly file I/O.

I copied this programme for "Teach yourself C...." but I'm getting
these warnings, although the prog does run.

///////////////////////////////////////////////////////////start of
prog
#include <stdio.h>

enum {SUCCESS, FAIL};

void CharReadWrite(FILE *fin, FILE *fout);

int main(void)
{
        FILE *fptr1, *fptr2;
        char fname1[]= "c:/vcpp/data_bytes.txt";
        char fname2[]= "c:/vcpp/outp_bytes.txt";
        int worked = SUCCESS;

        if ((fptr1 = fopen(fname1, "r")) == NULL){
                printf("Cannot open read file!");
                worked = FAIL;
        } else if ((fptr2 = fopen(fname2, "w")) == NULL){
                printf("Cannot open write file!");
                worked = FAIL;
        } else {
                CharReadWrite(fptr1, fptr2);
                fclose(fptr1);
                fclose(fptr2);
        }
        return worked;

}

        // Function definition:
void CharReadWrite(FILE *fin, FILE *fout)
{
        int c;

        while ((c=fgetc(fin)) != EOF){
                fputc(c,fout);          // Write char to out-file.
                putchar(c);
        }

}

///////////////////////////end of prog.

Error messages are;

------ Build started: Project: file_read, Configuration: Debug Win32
------
Compiling...
cl : Command line warning D9035 : option 'Wp64' has been deprecated
and will be removed in a future release
file_read.cpp
c:\documents and settings\niv\my documents\visual studio 2008\projects
\file_read\file_read.cpp(15) : warning C4996: 'fopen': This function
or variable may be unsafe. Consider using fopen_s instead. To disable
deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\program files\microsoft visual studio 9.0\vc\include\stdio.h
(237) : see declaration of 'fopen'
c:\documents and settings\niv\my documents\visual studio 2008\projects
\file_read\file_read.cpp(18) : warning C4996: 'fopen': This function
or variable may be unsafe. Consider using fopen_s instead. To disable
deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\program files\microsoft visual studio 9.0\vc\include\stdio.h
(237) : see declaration of 'fopen'
c:\documents and settings\niv\my documents\visual studio 2008\projects
\file_read\file_read.cpp(32) : warning C4101: 'i' : unreferenced local
variable
Compiling manifest to resources...
Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
Copyright (C) Microsoft Corporation.  All rights reserved.
Linking...
Embedding manifest...
Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
Copyright (C) Microsoft Corporation.  All rights reserved.
Build log was saved at "file://c:\Documents and Settings\Niv\My
Documents\Visual Studio 2008\projects\file_read\Debug\BuildLog.htm"
file_read - 0 error(s), 4 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped
==========

Can someone tell me what to do to get rid of these warnings please?

I dabbled in C years ago, but the modern compilers seem to do a lot
more (like confuse!).

just ignore it :)
It is not a big deal if you use file pointer properly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top