首页 > 编程知识 正文

isspace()当str字符串中包含空格

时间:2023-05-06 20:02:40 阅读:225420 作者:2065

isspace() checks for white-space characters. In the "C" and "POSIX" locales, these are: space, form-feed ('f'), newline ('n'), carriage return ('r'), horizontal tab ('t'), and vertical tab ('v').

函数int isspace ( int c );

用于判断字符c是否是空字符,是空字符返回值为非0,不是空字符返回值为0

例子判断字符串字符是否为空,是空字符,则将空字符替换成'#'

#include<stdio.h>#include<ctype.h>int main(){char c;int i=0;char str[]="isspace test one";while(str[i]){c=str[i];if(isspace(c))c='#';putchar(c);i++;}return 0;}

运行结果:

zdg@ubuntu:/mnt/hgfs/SHAREZDG/C_PROJECT$ ./a.out isspace#test#onezdg@ubuntu:/mnt/hgfs/SHAREZDG/C_PROJECT$

 

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。