首页 > 解决方案 > 如何结束字符串提示的循环?

问题描述

我是编程初学者,目前正在研究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");
}
        

标签: ccs50

解决方案


推荐阅读