我是 React 世界的新手,正在学习 Refs。React 文档说:
Refs 提供了一种访问 DOM 节点或在 render 方法中创建的 React 元素的方法。
我认为我们可以对querySelector函数做同样的事情。
React 文档给出了一个示例,说明我们如何使用 Refs 来关注输入元素。
这是代码->
class CustomTextInput extends React.Component {
constructor(props) {
super(props);
// create a ref to store the textInput DOM element
this.textInput = React.createRef();
this.focusTextInput = this.focusTextInput.bind(this);
}
focusTextInput() {
// Explicitly focus the text input using the raw DOM API
// Note: we're accessing "current" to get the DOM node
this.textInput.current.focus();
}
render() {
// tell React that we want to …Run Code Online (Sandbox Code Playgroud)我是编程和学习C编程基础知识的新手.我正在学习如何scanf()运作但我觉得现在我非常困惑,真的不知道如何以及要问什么.但我会尽力将问题清楚.
scanf并且当它们不是并且最大的问题时:它们是如何被跳过的?随着空白概念,我无法理解scanf功能的工作吗?我在许多书籍和网站以及本网站上都已经阅读过它,但它让我更加困惑,因为每个人都有自己的方式来讲述任何概念,并且它们各不相同.
看看这个简短的程序:
#include<stdio.h>
int main()
{
int num;
char ch;
printf("enter the value of num and ch:\n");
scanf("%d",&num);
scanf("%c",&ch);
printf("num = %d and ch = %c",num,ch);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我知道,在这个程序的用户将被允许进入的价值num,因为停留早在输入缓冲器和下一次换行字符而已,scanf将输入新行字符,但是可以解决,如果我们之前添加额外的空间%c中第二个scanf函数.
但是当我用char ch变量替换时int ch,scanf跳过新行.为什么?
为什么scanf不像空格一样跳过非空格字符例如 - a,b,c,d,@)#etc?
space和newline角色有scanf什么区别?我的意思是会有一些例外吗?我陷入了书中的问题.问题是 -
典型的互联网新手是一个名字B1FF,他有一种独特的编写消息的方式.这是一个典型的B1FF公报:
H3Y DUD3,C 15 R1LLY C00L
写一个"B1FF过滤器",读取用户输入的消息并翻译它进入B1FF说话:
输入消息:嘿伙计,C很酷,
在B1FF说话:H3Y DUD3,C 15 R1LLY C00L
你的程序应该将消息转换为大写字母,替换某些字母的数字(A = 4,B = 8,E = 3,I = 1,O = 0,S = 5).
我的节目 -
#include<stdio.h>
int main()
{
char arr[50]={0},ch[50]={0};
int i=0;
printf("\nenter the sentence : ");
while(arr[i-1]!='\n')
{
scanf("%c",&arr[i]);
i++;
}
i=0;
while(arr[i]!='\n')
{
if(arr[i]=='e')
ch[i]='3';
if(arr[i]==('A'||'a') )
ch[i]='4';
if(arr[i]==('B'||'b'))
ch[i]='8';
if(arr[i]==('I'||'i'))
ch[i]='1';
if(arr[i]==('o'||'O'))
ch[i]='0';
if(arr[i]==('S'||'s'))
ch[i]='5';
else ch[i]=arr[i]-32;
i++;
}
ch[i]='\n';
i=0;
printf("\nIn B1FF-SPEAK : ");
while(ch[i]!='\n')
{
printf("%c",ch[i]);
i++;
}
printf("\n"); …Run Code Online (Sandbox Code Playgroud)