这是我的代码:
// SysProAss1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <ctype.h>
int _tmain(int argc, _TCHAR* argv[])
{
{
char line[20];
//Asking the User to input some characters to use in the program
printf("Enter a few characters please:\n");
scanf_s("%s", line);
//For loop to print each character of the string on a new line
for (int i = 0; line[i]; ++i)
{
// If statement to check whether the character is an upper case vowel
if (line[i] == 'A' || line[i] == 'E' || line[i] == 'I' || line[i] == 'O' || line[i] == 'U')
printf("%c is an upper case vowel.\n", line[i]);
// If statement to check whether the character is a lower case vowel
else if (line[i] == 'a' || line[i] == 'e' || line[i] == 'i' || line[i] == 'o' || line[i] == 'u')
printf("%c is a lower case vowel.\n", line[i]);
// ispunct() function used to check whether the input character is a punctuation
else if (ispunct(line[i]))
printf("%c is a punctuation character. \n", line[i]);
// Else statement to print the character if it does not fit the above if statements
else
printf("%c\n", line[i]);
}
}
}
代码将编译,但是当我输入字符时,不打印任何内容。我已经测试过,在输入一些字符后,字符串是否包含任何内容,而不是。任何帮助都是适当的
答案 0 :(得分:1)
将代码中的scanf_s
语句更改为scanf_s("%s", line, sizeof(line));