user-0 提问: 为什么写进去输出不了，就是检验不了是不是乱输入的，求解救

回复:
user: user-1
content: if(strcmp(p->data.sex,"男")!=0 && strcmp(p->data.sex,"女")!=0)

user: user-0
content: scanf("%s",p->data.sex); 			if(strcmp(p->data.sex,"男")!=0 || strcmp(p->data.sex,"女")!=0) 			{ 				printf("性别只有男和女，请重新输入！\n");                    //显示也是错误的啊这是为啥 				goto lab2; 			}

user: user-2
content: scanf 的返回值不表示你输入的数，而是成功接收参数的个数  http://en.cppreference.com/w/c/io/fscanf

user: user-1
content: 仅供参考：#include <stdio.h> int main() {     int IP[4];     int i;     char c;      printf("请输入一个ip地址:");fflush(stdout);     while (1) {         rewind(stdin);         if (5==scanf("%d.%d.%d.%d%c",&IP[0],&IP[1],&IP[2],&IP[3],&c)) {             if (0<=IP[0] && IP[0]<=255              && 0<=IP[1] && IP[1]<=255              && 0<=IP[2] && IP[2]<=255              && 0<=IP[3] && IP[3]<=255              && '\n'==c) {                 break;             } else printf("输入的ip地址格式不对!\n请重新输入:\n");         } else printf("输入的ip地址格式不对!\n请重新输入:\n");     }     for (i=0;i<4;i++) {         printf("IP[%d]=%d\n",i,IP[i]);     }     return 0; }

user: user-3
content: 性别若是字符串，去掉scanf时的&, 另外，strcmp的返回值，若是相等则返回0；

user: user-4
content: ret1=scanf("%s",&p->data.age);   //scanf返回值是成功读取的个数，并不是读取到的数值 // age是int类型用 %d，而不是%s //if(ret1<=0) if(p->data.age <= 0)  scanf("%s",&p->data.sex);  //看下面的语句，那么sex应该是一个char*，那么p->data.sex就不需要使用& if(strcmp(p->data.sex,"男")!=1 || strcmp(p->data.sex,"女")!=1) //strcmp的返回值0表示相等，所以这里判断应该是 != 0

user: user-1
content: scanf, wscanf Read formatted data from the standard input stream.  int scanf( const char *format [,argument]... );  int wscanf( const wchar_t *format [,argument]... );  Routine Required Header Compatibility  scanf <stdio.h> ANSI, Win 95, Win NT  wscanf <stdio.h> or <wchar.h> ANSI, Win 95, Win NT    For additional compatibility information, see Compatibility in the Introduction.  Libraries  LIBC.LIB Single thread static library, retail version  LIBCMT.LIB Multithread static library, retail version  MSVCRT.LIB Import library for MSVCRT.DLL, retail version    Return Value  Both scanf and wscanf return the number of fields successfully converted and assigned; the return value does not include fields that were read but not assigned. A return value of 0 indicates that no fields were assigned. The return value is EOF for an error or if the end-of-file character or the end-of-string character is encountered in the first attempt to read a character.  Parameters  format  Format control string  argument  Optional arguments  Remarks  The scanf function reads data from the standard input stream stdin and writes the data into the location given by argument. Each argument must be a pointer to a variable of a type that corresponds to a type specifier in format. If copying takes place between strings that overlap, the behavior is undefined.  wscanf is a wide-character version of scanf; the format argument to wscanf is a wide-character string. wscanf and scanf behave identically otherwise.   Generic-Text Routine Mappings  TCHAR.H Routine  _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined  _tscanf scanf scanf wscanf    For more information, see Format Specification Fields — scanf functions and wscanf Functions.   Example   /* SCANF.C: This program uses the scanf and wscanf functions   * to read formatted input.   */  #include <stdio.h>  void main( void ) {    int   i, result;    float fp;    char  c, s[81];    wchar_t wc, ws[81];     printf( "\n\nEnter an int, a float, two chars and two strings\n");     result = scanf( "%d %f %c %C %s %S", &i, &fp, &c, &wc, s, ws );    printf( "\nThe number of fields input is %d\n", result );    printf( "The contents are: %d %f %c %C %s %S\n", i, fp, c, wc, s, ws);     wprintf( L"\n\nEnter an int, a float, two chars and two strings\n");     result = wscanf( L"%d %f %hc %lc %S %ls", &i, &fp, &c, &wc, s, ws );    wprintf( L"\nThe number of fields input is %d\n", result );    wprintf( L"The contents are: %d %f %C %c %hs %s\n", i, fp, c, wc, s, ws); }   Output  Enter an int, a float, two chars and two strings 71 98.6 h z Byte characters  The number of fields input is 6 The contents are: 71 98.599998 h z Byte characters  Enter an int, a float, two chars and two strings 36 92.3 y n Wide characters  The number of fields input is 6 The contents are: 456 92.300003 y n Wide characters   Floating-Point Support Routines, Stream I/O Routines, Locale Routines  See Also   fscanf, printf, sprintf, sscanf