如何在Visual C ++中检查文件的删除结束 [英] How to check end of file detuction in visual C++

查看:100
本文介绍了如何在Visual C ++中检查文件的删除结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我如何在从文件中读取记录时检查vc ++中文件结尾的概念。在这里,我附上了我的脚本......它已成功编译。但执行此程序时出现运行时错误...



我尝试过:



Can you please tell me that how to check the end of file concept in vc++ while reading the records from the file. Here I attached my script... it's compiled successfully. But a run time error is occurred while executing this program...

What I have tried:

// KillUser.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "malloc.h"
#include <string.h>
#include <process.h>
#include <stdio.h>

int main()
{
	FILE *p;
	char user[20];
	char cmd1[100], cmd2[100];
	//int errorCode;

	/*clrscr();*/

		strcpy_s(cmd1, "TASKKILL /F /FI \"USERNAME eq ");
		strcpy_s(cmd2, " /IM ntbshell.exe");

		/*char cmd1[] = "TASKKILL /F /FI \"USERNAME eq ";
		char cmd2[] = " /IM ntbshell.exe";*/

		/*printf("%s",cmd2);
		getch();*/
		
		errno_t errorCode = fopen_s(&p,"c:\\ERPLN\\TaskControl\\InforControlUser.txt", "r");
		
		while (!feof(p))
		{
			fscanf_s(p, "%s", &user);
			//printf("%s",user);

			strcat_s(user, "\"");

			strcat_s(cmd1, user);
			strcat_s(cmd1, cmd2);
			printf("%s\n", cmd1);
			//system(cmd1);
			//getch();

			strcpy_s(cmd1, "TASKKILL /F /FI \"USERNAME eq ");
			strcpy_s(cmd2, " /IM ntbshell.exe");

			/*char cmd1[] = "TASKKILL /F /FI \"USERNAME eq ";
			char cmd2[] = " /IM ntbshell.exe";*/
		}
		fclose(p);
		/*system("TASKKILL /F /IM notepad.exe");*/
		return 0;
	}

推荐答案

fscanf_s(p, "%s", &user);



你不应该在数组名称上使用addressof运算符(& user 。它应该是:


You should not use the addressof operator (&) on the array name user. It should just be:

fscanf_s(p, "%s", user); // no leading &


这篇关于如何在Visual C ++中检查文件的删除结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆