这是我正在处理的作业问题:
声明一个字符变量letterStart。编写一条将用户的字母读入letterStart的语句,然后是输出该字母和字母表中下一个字母的语句。以换行符结尾。提示:字母以其ASCII码形式存储,因此加1会产生下一个字母。假定用户输入“ d”的示例输出:de
#include <stdio.h>
int main(void) {
char letterStart;
scanf("%c", letterStart);
printf("%c", letterStart);
printf("%c", letterStart + 1);
return 0;
}
您的输出=(未知字符)
而作业编译器要测试'a',则输出为ab。
有什么提示吗?
答案 0 :(得分:1)
您在
上忘记了import React from 'react'
export default class CollectionComponent extends React.Component {
constructor(props) {
super(props)
this.state = {
results: this.props.results,
hoveredId: null
}
}
onMouseEnter({ listingId }) {
this.setState({ listingId });
}
onMouseLeave() {
this.setState({ listingId: null });
}
render() {
const {results, IndividualResult, perPage, options} = this.props
return (
<div className="paginated-results">
{this.state.results.map( result =>
<IndividualResult key={result.id} hoveredId={this.state.hoveredId} result={result} options={options} onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave}/>
)}
</div>
)
}
}
符号
&
制作:-
scanf("%c", letterStart);
修改后的代码:-
scanf("%c", &letterStart);
输出:-
#include <stdio.h>
int main(void) {
char letterStart;
scanf("%c", &letterStart);
printf("%c", letterStart);
printf("%c", letterStart + 1);
return 0;
}
答案 1 :(得分:1)
打开编译器警告:
$ gcc main.c -Wall -Wextra
main.c: In function ‘main’:
main.c:7:12: warning: format ‘%c’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat=]
scanf("%c", letterStart);
^
main.c:7:4: warning: ‘letterStart’ is used uninitialized in this function [-Wuninitialized]
scanf("%c", letterStart);
^~~~~~~~~~~~~~~~~~~~~~~~
在那里您看到了问题。更改为scanf("%c", &letterStart);