小编Yuv*_*val的帖子

如何在C中为单个字符执行scanf

在C:我正在尝试从用户获取char scanf,当我运行它时程序不等待用户输入任何东西......

这是代码:

char ch;
printf("Enter one char");
scanf("%c", &ch);
printf("%c\n",ch);
Run Code Online (Sandbox Code Playgroud)

为什么不工作?

c scanf char

91
推荐指数
4
解决办法
37万
查看次数

C中的"短"数据类型是什么?

在以下功能中:

void AddWordData(FILE* dataFile, short word, int* dc)
{
    fprintf(dataFile, "%06o\n", word);
    ++(*dc);
} 
Run Code Online (Sandbox Code Playgroud)

该功能正在变短.我在网上做了一些搜索,但发现只有短整数.当一个函数得到一个短类型时它意味着什么?它的数据类型是什么?

c short

11
推荐指数
1
解决办法
5万
查看次数

函数计算哈希数,它到底是做什么的,为什么?

我知道这个函数正在用哈希数做一些事情,但是没有完全理解这个函数的用途?为什么"res*31 +*key"?为什么31?

unsigned int HashAlg(char* key)
{
    unsigned int res = 0;

    while (*key != 0)
    {
        res = res * 31 + *key;
        ++key;
    }

    return res;
}
Run Code Online (Sandbox Code Playgroud)

c hash

5
推荐指数
2
解决办法
112
查看次数

编译打印一个字符串函数给出错误信息 - C.

我想在C中编写一个简单的main函数,它接收两行字符串输入并在屏幕上打印它们.这是我写的代码:

int main()
{
    char a[100];
    char b[100];
    printf("Enter the first string:\n");
    fgets(a,100,stdin);
    printf("Enter the second string:\n");
    fgets(b,100,stdin);
    printf("\n\n THE FIRST STRING IS:  %S\n\n THE SECOND STRING IS:%S",a, b);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我尝试编译时,我收到此错误消息:

gcc -g -Wall PN52.c -o myprog
PN52.c: In function ‘main’:
PN52.c:12:2: warning: format ‘%S’ expects argument of type ‘wchar_t *’, but argument 2 has type ‘char *’ [-Wformat]
PN52.c:12:2: warning: format ‘%S’ expects argument of type ‘wchar_t *’, but argument 3 has type ‘char *’ [-Wformat]
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助

c string printf

4
推荐指数
1
解决办法
475
查看次数

计算两个日期之间的闰日数

我已经写下了这段代码,我的程序对象是计算两个给定日期和时间之间的分钟数.让我们说分钟之间的差异:

14/1/2016 23:18
and
14/1/2004 23:18
is:
6,311,520.00 minutes 
Run Code Online (Sandbox Code Playgroud)

这是我写的代码:

我在计算中有一些错误,从我发现我的问题最多是1440分钟与正确答案的差异 - 由excel检查.我认为我的问题在于计算两个日期之间的LEAP DAYS:

    #include <stdio.h>

    typedef struct {
        int year;
        int month;
        int day;
        int hour;
        int minute;
        int second;     
    }time;
    time time1,time2;

long calcTime(time,time);
int calcDaysFromStart(int,int);
int leapcheck(int);

int main()
{

    printf("Hello\n");
    printf("For calculating the difference between two times:\n");
    printf("Enter the date for first time:\n");
    printf("Enter day:\n");
    scanf("%d",&time1.day);
    printf("Enter month:\n");
    scanf("%d",&time1.month);
    printf("Enter year:\n");
    scanf("%d",&time1.year);
    printf("Enter the exact hour for first time:\n");
    printf("Enter the hour:\n");
    scanf("%d",&time1.hour);
    printf("Enter the minutes:\n"); …
Run Code Online (Sandbox Code Playgroud)

c time datediff

1
推荐指数
1
解决办法
2046
查看次数

条件是如何使用的?

以下C代码中的以下条件是什么意思?

if (line[currChar] == '\"')
Run Code Online (Sandbox Code Playgroud)

c if-statement escaping

-5
推荐指数
1
解决办法
85
查看次数

标签 统计

c ×6

char ×1

datediff ×1

escaping ×1

hash ×1

if-statement ×1

printf ×1

scanf ×1

short ×1

string ×1

time ×1