-3

Cの文字で単語を比較しようとしています.

私のコードは次のとおりです。

char kel[100];
char check[7];

check is random 8 letter

printf("Please Enter the Word:");
    scanf("%s", &kel); 



for(int k = 0; k < 7; k++) 
     {
         for(int j = 0; j < size; j++)
         {
             if(check[i] != kel[i])
             {
                  printf("Different");   
             }
         }
     }

ケル語でランダムな文字をチェックしたい。ランダムな文字が kel に含まれていない場合は、警告を発したいと思います。

どうやってやるの?

ありがとう、ジョン

4

3 に答える 3

0
int size = strlen(kel);

for(int k = 0; k < 8; k++) 
{
    int j;

    for(j = 0; j < size; j++)
    {
        if(check[k] == kel[j])
        {
            break;
        }
     }

     if(j == size)
         printf("Warning: different!");
 }
于 2013-06-07T08:29:18.563 に答える
0

多分

#include <string.h>

if(NULL==strpbrk(kel, check)){
    printf("not include");
}
于 2013-06-07T08:27:32.797 に答える
0

マジックナンバーを使用しないでください。これが役立つことを願っています

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

#define MAX 7

int main(void)
{
    char kel[100] = {0};
    char check[MAX];
    int i, j;

    printf("Please Enter the Word:");
    scanf("%s", kel); /* You don't need &, kel is already a pointer */
    srand((unsigned int)time(NULL));
    printf("Your random is:");
    for (i = 0; i < MAX; i++) {
        check[i] = 31 + rand() % 96; /* This will give you printable ASCIIs */
        putchar(check[i]);
    }
    putchar('\n');
    for (i = 0; i < MAX; i++) {
        for (j = 0; j < MAX; j++) {
            if (check[i] == kel[j]) break;
        }
        if (j == MAX) printf("Different %c\n", check[i]);
    }
    return 0;
}
于 2013-06-07T08:37:04.063 に答える