c - 如何结束字符串提示的循环?
问题描述
我是编程初学者,目前正在研究C。
我正在尝试提示用户输入。我正在尝试获取的输入是来自他们的一段文本。但是只要给出一个句子,程序就会不断提示,并且循环不会停止。输入文本后,我该怎么做才能停止循环?
这是我到目前为止得到的:
#include <cs50.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
int main(void)
{
//Prompt user for input
long p;
int s;
do
{
p = get_long ("Insert Text Here: ");
scanf("%li \n", &p);
p = (char) p;
}
while ((p < 'a' && p > 'Z') || (p < 'A' && p > 'Z'));
//Analyze The Grade Level
s = 0;
while (s < p)
{
s++;
printf ("s: %i \n", s);
}
printf ("\n");
}
解决方案
推荐阅读
- python - 无头 chrome 是否支持 MacOS 原生通知?
- java - gradle.properties 中的多行字符串
- python - 如何在熊猫中将多行折叠为一
- html - 来自 MediaStreamDestination 的克隆流是否仍以某种方式绑定到此 AudioNode?
- javascript - 为什么没有从数据库中获取 salt 和 hash 值?- 节点JS
- fpga - Vivado:TCL 命令将时钟 1 和时钟 2 之间的时序路径设置为假路径(TIMING-6 和 TIMING-7)
- css - CSS 优先级。Div 元素颜色没有改变
- javascript - Div 内的内联内容
- domain-driven-design - 对多个聚合应用相同的操作
- javascript - 浏览器中支持 AJAX 的导航按钮