怎样在读取字符串时跳过空格

在c++中,怎样在读取字符串时跳过空格
如:56 1k uio 42

怎样用字符数组接收:561kuio42

第1个回答  2015-07-02
通过char字符判断是否==' '。如果是空格字符跳过。

例程:
#include <stdio.h>

#include <string.h>
int main (){
char letter;
printf("Please input a letter:");
do { scanf("%c",&letter);} while( letter == ' ' ); //当是空格是,继续读
if(letter>=97&&letter<=122)
printf("%c",letter-32);
else
printf("%c",letter);
return 0;
}本回答被网友采纳
相似回答