Re: fwrite a hidden file



Now that you show more of the code, you only confirm my view that you are utterly and
totally clueless about how to write even a simple readfile-writefile program. You cannot
be trusted to write a program that modifies a critical system file.

Learn to program first. After that, you can start asking questions on ways to reliably
modify real files, and after you've demonstrated ability there, you might be trusted to
write a critical system file.
joe
On Mon, 25 Jun 2007 20:19:00 -0700, Hayes <Hayes@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

hi all~
now i try to use "fgets" and "fwrite" to read and modify a file
but if i set the file hidden
i would get error message
"Microsoft Visual Studio C Runtime Library has detected a fatal error in
*.exe"

code:

FILE* file;
char data[512];
*****
Stupid idea. Why a fixed-size array?
*****
CString content[128];
*****
Even more stupid. Why not a CStringArray?
*****
int row=0;

file = fopen("C:\\text.txt", "rt");
****
You have got to be really dumb here. YOU DIDN'T CHECK TO SEE IF IT WORKED!!!!! This is
more than a newbie mistake. This is just irresponsible programming. Even someone writing
fopen for the first time sees that in almost any example, there is a requirement for
seeing if it worked.

Otherwise, all my previous comments still apply. You are in NO WAY qualified to write
code that would modify boot.ini. Not until you learn how to program should you be going
anywhere NEAR that file.
joe
*****
****

while( fgets(data, 512, file) != NULL )
{
content[row++].Format("%s", data);
}
fclose(file);

if( content[row-1].Find( " /noguiboot /bootlogo" ) != -1 )
{
content[row-1].Replace(" /noguiboot /bootlogo", "");
file = fopen("C:\\text.txt", "wt+");
int line = 0;
while(line != row)
{
fwrite(content[line], sizeof(char), content[line].GetLength(), file);
line++;
}
fclose(file);
}

I don't know what to do to resolve it.
maybe something's wrong..
thanks for help~
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages


Loading