Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 测试运行null和字母?_C_Visual Studio 2013 - Fatal编程技术网

C 测试运行null和字母?

C 测试运行null和字母?,c,visual-studio-2013,C,Visual Studio 2013,我想自动测试运行NULL作为变量和字母,但是我不知道我做错了什么 这是我的密码: #include <stdlib.h> #include <stdio.h> int inuti(double x, double y, double x1, double y1, double x2, double y2) { int x_inuti; int y_inuti; if (x1 < x2) x_inuti = x > x

我想自动测试运行NULL作为变量和字母,但是我不知道我做错了什么

这是我的密码:

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

int inuti(double x, double y, double x1, double y1, double x2, double y2) {
    int x_inuti;
    int y_inuti;

    if (x1 < x2)
        x_inuti = x > x1 && x < x2;
    else
        x_inuti = x > x2 && x < x1;
    if (y1 < y2)
        y_inuti = y > y1 && y < y2;
    else
        y_inuti = y > y2 && y < y1;
    return x_inuti && y_inuti;
}

int main(void) {
    double x, y, x1, y1, x2, y2;
    char text_y, text_x1, text_y1, text_x2, text_y2;
    char text_x;
    int resultat;
    int i;
    for (i = 0; i < 1; i++)
    {

    text_x = "lalala";
    text_y = "lala";
    text_x1 = "text";
    text_y1 = "";
    text_x2 = "";
    text_y2 = "";


        printf("punktens x-varde: %.1f \n", text_x);


        printf("punktens y-varde: %.1f \n", text_y);

        printf("\n");

        printf("Ena hornets x-varde: %.1f \n", text_x1);


        printf("Ena hornets y-varde: %.1f \n", text_y1);

        printf("\n");

        printf("Andra hornets x-varde %.1f \n", text_x2);


        printf("Andra hornets y-varde %.1f \n", text_y2);

        printf("\n");

        resultat = inuti(text_x, text_y, text_x1, text_y1, text_x2, text_y2);


        if (resultat == 1)
            printf("Punkten var inuti rektangeln.\n");
        else if (resultat == 0)
            printf("Punkten var utanfor rektangeln.\n");

        printf("\n");
        printf("\n");
    }
    //Here I'm testing all number variables - This works fine
    for (x = -10; x <= 10; x++) {
            for (y = -10; y <= 10; y++) {
                for (x1 =-10; x1 <= 10; x1++) {
                    for (y1 = -10; y1 <= 10; y1++) {
                        for (x2 = -10; x2 <= 10; x2++) {
                            for (y2 =-10; y2 <= 10; y2++){

                                printf("punktens x-varde: %.1f \n", x);


                                printf("punktens y-varde: %.1f \n", y);

                                printf("\n");

                                printf("Ena hornets x-varde: %.1f \n", x1);


                                printf("Ena hornets y-varde: %.1f \n", y1);

                                printf("\n");

                                printf("Andra hornets x-varde %.1f \n", x2);


                                printf("Andra hornets y-varde %.1f \n", y2);

                                printf("\n");

                                resultat = inuti(x, y, x1, y1, x2, y2);


                                if (resultat == 1)
                                    printf("Punkten var inuti rektangeln.\n");
                                else
                                    printf("Punkten var utanfor rektangeln.\n");

                                printf("\n");
                                printf("\n");


                            }
                        }
                    }
                }
            }
        }

        getchar();
    return 0;
}
#包括
#包括
int inuti(双x,双y,双x1,双y1,双x2,双y2){
int x_inuti;
因纽蒂国际酒店;
if(x1x1&&xx2&&xy1&&yy2&&ychars上循环
char
类型虽然通常用于存储字符,但被实现为一个小整数。它可以有不同的最小值和最大值。您可以
#include
,然后使用宏
char\u min
char\u max
来查找值。在大多数计算机上,这些值分别等于0和255

您可以通过以下方式测试
char
的所有可能值:

#include <limits.h>
#include <ctype.h>
#include <string.h>

然后它看起来像是在存储一个
a
,但编译器只是获取
a
的数值并将其存储在
mychar
中。几乎每个人都使用ASCII,其中
'a'==97
。因此在使用ASCII时,这一行与上面的行相同,尽管更为神秘:

char mychar = 97;
某些数字与可打印字符不对应,或者可能根本不是字符,具体取决于您的字符编码

试图在
字符中存储任何其他内容
C中的变量从来都不是“空的”任何数值类型,包括
char
,都不能有空值。如果不为变量设置值,它们要么等于零,要么未定义,具体取决于您声明变量的方式。指针可以是
NULL
,这与将指针设置为零相同


您的行
text\u x=“lalala”
将不起作用,因为
text\u x
只能容纳一个字符。
“lalalala”
返回一个指向
字符数组的指针。编译器应该抱怨被要求将指针投射到
字符中。
text\u x=“”也是如此
:编译器返回一个指向空字符串的指针,并尝试将其存储在
text_x
中,这将不起作用。

C类型不可为空。是否尝试在所有数据类型中存储
NULL
?这将不起作用。此外,
char
数据类型只能包含一个数字,介于0和255之间。这对于一个数据类型来说足够大ASCII字符,但不能在其中存储字符串。你能澄清一下你想做什么吗?@yellowantphil我正在测试运行输入,但它必须是自动的。我自动测试运行不同的值。我测试运行所有数字组合没有问题,但我不知道如何测试运行字母和(如果值为空)空。我尝试了许多不同的方法,但我无法找到它。只有在打印type
double
时才使用
%f
。char text\u x是字母还是数字?
text\u x
只是类型
char
的一个变量。这是编译器所知道的所有内容。您通常会在其中存储字符,但也可以输入数字d很直接。我会扩展一下答案。谢谢你这么漂亮的解释。正如我之前提到的,我已经可以测试运行数字了。我想做的是测试运行字母。我想把变量改成可以存储字母的。我想那
char
只存储字母,但我现在知道了它可以将它们转换成numbers.有什么类型可以存储字母吗?@John不太可能。计算机只能存储数字,任何编程语言都是如此。C只是将字母映射到数字(
'a'==97
)比其他一些语言更明显。如果您只想测试特定字符,这也不难。我会将其添加到我的答案中,因为一个示例只有几行代码。@John好的,这需要两行以上的代码。只需按照我在答案中添加的方式在数组中循环字符即可。这样您就不必担心任何问题了关于字符的数值。
char text_x;
char my_favorite_characters[] = "abcdefgABCDEFG0123456789.+-";
int i, imax;
imax = strlen(my_favorite_characters);
for (i = 0; i < imax; i++) {
    text_x = my_favorite_characters[i];
    printf("%c is one of my favorite characters\n", text_x);
}
char mychar = 'a';
char mychar = 97;