我正在尝试创建一个动态变化的表。其列数根据月份的天数(28、29、30 或 31)而变化。
我手动创建了表(但列数固定为31):
https://i.stack.imgur.com/pAvPu.png
这是我尝试根据当前月份的天数(28,29,30,31)手动选择列数的组件,它在浏览器中没有显示任何内容:
const Test = () => {
// Number of days in the current month
function daysInCurrentMonth() {
var now = new Date();
return new Date(now.getFullYear(), now.getMonth()+1, 0).getDate();
}
let a = daysInCurrentMonth();
return (
<div>
<table>
<tbody>
<tr>
{() => {
for(let i=1;i<=a;i++){
<td>{i}</td>
}
}}
</tr>
</tbody>
</table>
</div>
);
}
export default Test;
Run Code Online (Sandbox Code Playgroud)
如何在这段代码中使用for循环?
锻炼:
编写一个函数,在作为参数给出的 CH2 字符串的末尾添加 CH1 字符串后,返回一个 CH 字符串。
这是我的代码:
#include <stdio.h>
#include <stdlib.h>
char *ajout(char ch1[], char ch2[]);
int main() {
char ch1[] = "hello";
char ch2[] = "ooo";
char *ch = ajout(ch1, ch2);
printf("%s",ch);
return 0;
}
char *ajout(char ch1[], char ch2[]) {
char *ch;
int nb = 0;
for (int i = 0; ch1[i] != '\0'; i++) {
ch[i] = ch1[i];
nb++;
}
int i = 0;
for (i; ch2[i] != '\0'; i++) {
ch[nb] = ch2[i];
nb++; …Run Code Online (Sandbox Code Playgroud) 这是代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int appar(char c[], char x);
int main() {
char c[] = "hello everyone !";
int b = appar(c, 'h');
printf("nbr of h is %d ", b);
return 0;
}
int appar(char c[], char x) {
int i = 0, cmpt = 0;
int q = strlen(c);
for (i; i < q; i++) {
if (c[i] == 'x')
cmpt++;
}
return cmpt;
}
Run Code Online (Sandbox Code Playgroud)
我运行并编译程序,但我收到“h 的 nbr 为 0”
我的代码有什么问题?