我是C编程新手。我的任务之一是让我很难过。这是:
编写一个ANSI-C程序,它使用getchar()从标准输入中读取字符,并使用putchar()仅输出标准输出的输入中的字母,空格('')和换行符。如果字母是小写字母,您的程序应将它们转换为大写字母。例如,给出以下输入:
SQL-query:
CREATE TABLE `UG_blogs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`catid` int(11) NOT NULL,
`ownerid` int(11) NOT NULL,
`content` text NOT NULL,
`date` datetime NOT NULL DEFAULT TIMESTAMP,
PRIMARY KEY (`id`), KEY id(`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;
MySQL meldt: Documentatie
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '
PRIMARY KEY (`id`), KEY id(`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT C' at line 6
你的程序输出应该是:
There are 6 apples and 8 oranges, also 9 bananas ...... @ Apple Store!! See you there!?
我可以让大写部分正确,但我很难忽略数字和任何其他角色。任何帮助将不胜感激。
THERE ARE APPLES AND ORANGES ALSO BANANAS APPLE STORE SEE YOU THERE
答案 0 :(得分:2)
在 EventListener genericListener = new StorageFileEventListener("MyIoTListener");
genericListener.EnableEvents(Logger.Log, EventLevel.Critical);
中使用isalpha
,isspace
和toupper
像这样
<ctype.h>
答案 1 :(得分:0)
只需使用isdigit功能检查字符是否为数字。如果它不是数字,请按照您现在的处理方式进行处理。否则,只需忽略它并尝试读取另一个字符。
答案 2 :(得分:0)
你可以使用类似的东西:
char char_filter(char c)
{
/* lower case letters */
if (c >= 'a' && c <= 'z')
return c - ('a' - 'A');
/* upper case letters*/
if (c >= 'A' && c <= 'Z')
return c;
/* space and new line */
if (c == ' ' || c == '\n')
return c;
/* other characters */
return 0;
}
此处如果函数返回零,则应跳过char,否则应由putchar
打印:
char c;
while ((c = getchar()) != EOF) {
if ((c = char_filter(c)))
putchar(c);
}
请注意,还有标准函数int islower(int c)
,int isupper(int c)
和int isspace(int c)
。函数isspace()
还将'\t'
,'\n'
和其他一些字符视为空格。