2015-11-03 200 views
0

这里不工作是我的代码:代码在代码::块在Visual Studio 2013

// 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]); 

    } 

} 

}

的代码可以编译,但是当打印我的输入字符什么。我已经测试过,看看输入一些字符后字符串是否包含任何内容,而不是。任何帮助将appriciated

+0

'scanf_s( “%s” 时,线);'需要的大小 - >'scanf_s( “%S” 线,20) ;' – BLUEPIXY

+0

是的,现在工作,非常感谢。我觉得有点愚蠢:) – Tom

+0

请问我可以如何实现另一个if语句,以便能够识别重复字符,例如。 b,b - 重复字符。 – Tom

回答

1

变化scanf_s声明在代码中,scanf_s("%s", line, sizeof(line));