在C:我正在尝试从用户获取char scanf,当我运行它时程序不等待用户输入任何东西......
这是代码:
char ch;
printf("Enter one char");
scanf("%c", &ch);
printf("%c\n",ch);
Run Code Online (Sandbox Code Playgroud)
为什么不工作?
在以下功能中:
void AddWordData(FILE* dataFile, short word, int* dc)
{
fprintf(dataFile, "%06o\n", word);
++(*dc);
}
Run Code Online (Sandbox Code Playgroud)
该功能正在变短.我在网上做了一些搜索,但发现只有短整数.当一个函数得到一个短类型时它意味着什么?它的数据类型是什么?
我知道这个函数正在用哈希数做一些事情,但是没有完全理解这个函数的用途?为什么"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中编写一个简单的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)
谢谢你的帮助
我已经写下了这段代码,我的程序对象是计算两个给定日期和时间之间的分钟数.让我们说分钟之间的差异:
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)