Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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 我分配了一个长变量,但错误消息声称它是int_C_Variables_Integer_Long Integer_Cs50 - Fatal编程技术网

C 我分配了一个长变量,但错误消息声称它是int

C 我分配了一个长变量,但错误消息声称它是int,c,variables,integer,long-integer,cs50,C,Variables,Integer,Long Integer,Cs50,我正在做一个作业,要求我处理信用卡号码,所以我一直在使用长变量,比如第14行的“o”,但我一直得到格式指定类型“long”,但当我试图打印时,参数的错误消息是“int”,我不知道为什么。我对编程很陌生,所以这可能只是初学者的错误,因此非常感谢您的帮助。在循环中 #include <stdio.h> #include <cs50.h> int main(void) { long card; do { card = get_long(

我正在做一个作业,要求我处理信用卡号码,所以我一直在使用长变量,比如第14行的“o”,但我一直得到格式指定类型“long”,但当我试图打印时,参数的错误消息是“int”,我不知道为什么。我对编程很陌生,所以这可能只是初学者的错误,因此非常感谢您的帮助。

在循环中

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    long card;
    do
    {
        card = get_long("Type crdit card number\n");
    }
    while (card < 0);
    long c = card;
    int i = 1;
    for (long o = 10; c >= 10;o *= 10, i++)
    {
        c = c / 10;
    }
    for (int h = 0, o = 10; h < i; h++, o *= 10)
    {
        c = card;
        c = c % o;
        printf("%ld\n", c);
        printf("%ld\n", o);
    }
}

非常感谢,但是,有没有办法在同一个for循环中声明两个不同类型的变量?
for (int h = 0, o = 10; h < i; h++, o *= 10)
{
    c = card;
    c = c % o;
    printf("%ld\n", c);
    printf("%ld\n", o);
}
for (long h = 0, o = 10; h < i; h++, o *= 10) /* use long instead of int */
{
    c = card;
    c = c % o;
    printf("%ld\n", c);
    printf("%ld\n", o);
}