2014-01-06 106 views
1

我得到这个错误两次,我不知道为什么,因为我有stdlib.h包括在开始 所以我不知道我是什么做错了或忘记添加? 任何人都可以看到它为什么可能显示出来吗? 错误:智能感知:标识符“的strlen”用C错误:智能感知:标识符“strlen”未定义t在C

#include <stdlib.h> 
#include <stdio.h> 
#include <time.h> 

FILE*fp; 

char *symbols = "#~!$%^&*()+=<>?/@"; //Random Symbol is generated form this list 

int main(void) { 

char password[4 + 4 + 2 + 2 + 1]; 
int i, j=0, len=sizeof(password)-1; 
int menuNum = 0; 
int passwordCheck[15+1]; 



fp = fopen("passwords.txt", "a+"); 
//Opens the text file to save the Passwords 

srand(time(NULL)); 
printf("  Main Menu\n"); 
printf("********************************\n"); 
printf("\nEnter 1 to Generate a New Password: "); 
printf("\n\n"); 
printf("Enter 2 to Check Old Passwords: "); 
printf("\n\n"); 
printf("Enter 3 to Exit. "); 
printf("\n\n"); 
scanf("%d", &menuNum); // reads number 

if (menuNum == 1) 
{ 
    printf("********************************\n"); 
    printf("\nYour New Password is: \n\n"); 

//Each Password will Have 12 Characters(4 Uppercase letters, 4 Lowercase letters, 2 Numbers & 2 Symbols) 

for (i = 0; i < 4; ++i) 
    password[j++] = 'a' + rand() % ('z' - 'a' + 1); //Generates 4 random Lowercase characters 

for (i = 0; i < 4; ++i) 
    password[j++] = 'A' + rand() % ('Z' - 'A' + 1); //Generates 4 random Uppercase characters 

for (i = 0; i < 2; ++i) 
    password[j++] = '0' + rand() % ('0' - '9' + 1); //Generates 2 random numbers 

for (i = 0; i < 2; ++i) 
    password[j++] = symbols[rand() % strlen(symbols)]; //Generates 2 random symbols 

password[j] = '\0'; 
for(i = 0; i < sizeof(password)-1; ++i) 
    { 
    char c = password[i]; 
    j = rand() % len; 
    password[i] = password[j]; 
    password[j] = c; 
    } 

printf("%s\n\n", password); 
printf("********************************\n"); 
fprintf(fp, "\n%s", password); //Outputs the Generated Passoword to the text file 
fclose(fp); //Closes the text file 
system("pause"); 
} 
else if (menuNum == 2) 
{   
    printf("\nEnter your password for checking: "); 
    scanf("%s", passwordCheck); // reads password 
    if (strlen(passwordCheck) > 15) // Checks length of Password 
    { 
     printf("'%s' is too long. Needs to be less then 15 Characters\n", passwordCheck); 
     system("pause"); 
    } 
    else if (strlen(passwordCheck) < 9) //Checks length of Password 
    { 
     printf("'%s' is too short. Needs to be more then 9 Characters\n", passwordCheck); 
     system("pause"); 
    } 
} 

} 
+2

顶'#包括'请。 – Maroun

回答

5

未定义您需要添加:

#include <string.h> 

当你想知道包括所需要的功能,阅读它的手册页。

+0

非常感谢:)。 – DigitalD

1

您需要#include <string.h>或strings.h在程序

这将导入的原型strlen函数