user-0 提问: 这是什么情况，有哪位大神指点一下

回复:
user: user-1
content: sscanf 从指定字符串输入，而fscanf 是从文件输入，下面是fscanf的应用#include<stdlib.h> #include<stdio.h> #include<string.h>  int main(void) {     FILE *file;     char name[123];     char password[123];     char name_tmp[123];     char password_tmp[123];     char name_pass[256];     char *ret;     int login_success = 0;      file = fopen("D:\\liu\\lx.txt","r+");     if (file == NULL)     {         printf("文件打开失败！");         return 1;     }      while(1)     {         printf("请输入用户名：");         scanf("%s",name);         printf("请输入密码：");         scanf("%s",password);          while(1)         { //            ret = fgets(name_pass,sizeof(name_pass),file); //            if (ret==NULL)      //判断文件有没有读取成功 //            { //                break; //            } // //            sscanf(name_pass,"%s %s",name_tmp,password_tmp);              fscanf(file,"%s %s",name_tmp,password_tmp);              if((strcmp(name,name_tmp) == 0) && strcmp(password,password_tmp) == 0)             {                 printf("登陆成功！\n");                 break;             }             else             {                 printf("用户名或密码错误！");                 system("pause");                 system("cls");                 break;             }         }     }     fclose(file);     return 0; }

user: user-1
content: 你的第12行char name_pass;应该是想定义成类似如下的字符数组的吧    char name_pass[256]; 这么修改，再加上头文件#include<stdlib.h>至少你贴出来的代码可以运行了，如下#include<stdlib.h> #include<stdio.h> #include<string.h>  int main(void) {     FILE *file;     char name[123];     char password[123];     char name_tmp[123];     char password_tmp[123];     char name_pass[256];     char *ret;      file = fopen("D:\\liu\\lx.txt","r+");     if (file == NULL)     {         printf("文件打开失败！");         return 1;     }      while(1)     {         printf("请输入用户名：");         scanf("%s",name);         printf("请输入密码：");         scanf("%s",password);          while(1)         {             ret = fgets(name_pass,sizeof(name_pass),file);             if (ret==NULL)      //判断文件有没有读取成功             {                 break;             }              sscanf(name_pass,"%s %s",name_tmp,password_tmp);              if((strcmp(name,name_tmp) == 0) && strcmp(password,password_tmp) == 0)             {                 break;             }             else             {                 printf("用户名或密码错误！");                 system("pause");                 system("cls");             }         }     }     return 0; }

user: user-0
content: 好的谢谢。在问一下，fscanf和sscanf的语法有什么区别

user: user-2
content: 能否把代码直接贴出来，测试现象可以截图嘛

user: user-0
content: #include<stdio.h> #include<string.h>  int main(void) { 	FILE *file; 	char name[123]; 	char password[123]; 	char name_tmp[123]; 	char password_tmp[123]; 	char name_pass; 	char *ret;  	file = fopen("D:\\liu\\lx.txt","r+"); 	if (file == NULL) { 		printf("文件打开失败！"); 		return 1; 	}  	while(1) { 		printf("请输入用户名："); 		scanf("%s",name); 		printf("请输入密码："); 		scanf("%s",password);  		while(1) { 			ret = fgets(name_pass,sizeof(name_pass),file); 			if (ret==NULL) {    //判断文件有没有读取成功 				break; 		}  			sscanf(name_pass,"%s %s",name_tmp,password_tmp);  		if((strcmp(name,name_tmp) == 0) && strcmp(password,password_tmp) == 0) { 			break; 		} else { 			printf("用户名或密码错误！"); 			system("pause"); 			system("cls"); 		} 		} 	} 	return 0;   下面是编译错误代码 aaa.c: In function 'main': aaa.c:26:4: warning: passing argument 1 of 'fgets' makes pointer from integer without a cast [enabled by default] In file included from aaa.c:1:0: c:\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/stdio.h:354:39: note: expected 'char *' but argument is of type 'char' aaa.c:31:4: warning: passing argument 1 of 'sscanf' makes pointer from integer without a cast [enabled by default] In file included from aaa.c:1:0: c:\mingw\bin\../lib/gcc/mingw32/4.7.1/../../../../include/stdio.h:348:37: note: expected 'const char *' but argument is of type 'char' aaa.c:42:2: error: expected declaration or statement at end of input