#include <iostream>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
using namespace std;
void leftshift(char*a, int n, int m);
int main()
{
char q = 0;
do{
char *a = (char *)malloc(20*sizeof(char));
memset(a,0,20);
int num = 0;
int times = 0;
if(q != 0)
getchar();
// cout << "Please input the string!" << endl;
printf("Please input the string\n");
gets(a);
while(a[num] != 0)
{
printf("%c %d\n",a[num],num);
num++;
}
// while(scanf("%c",a+num) && a[num] != "\0")
// {
// num++;
// }
cout << "The length of the input string " << num << endl;
cout << "Please input the number you want to shift!" <<
C/C++获取输入时的回车问题
最新推荐文章于 2024-09-03 17:32:42 发布
这篇博客探讨了在C/C++编程中处理输入时遇到的回车问题。通过示例代码展示了如何使用`gets()`和`scanf()`函数读取字符串,并确保在后续输入时不包含回车符。此外,还介绍了一个名为`leftshift`的函数,用于将字符串左移指定次数,以及在读取用户输入时如何处理非正数的情况。
摘要由CSDN通过智能技术生成