About char! | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

About char!

#include <stdio.h> #include <string.h> int main() { char syr[10]="hi hello "; char *p=NULL; p=syr; for(int i=0;i<=10;i++) { if(strcmp(*(p+i)," ")==0) {printf("1");} else {printf("0");} } return 0; } I want to make a code that prints 1 when there is space. But I don't know how to compare each letters....

24th Jan 2020, 11:34 PM
전은지
전은지 - avatar
2 ответов
+ 3
You can either compare the value directly by using the comparison operator if ( *( p + i ) == ' ' ) ... or by making use of the isspace() function provided by the standard library, e.g. if ( isspace( *( p + i ) ) ) ... https://en.cppreference.com/w/c/string/byte/isspace
24th Jan 2020, 11:45 PM
Shadow
Shadow - avatar
+ 2
Have a look at "isspace" from the "ctype.h" header file; http://www.cplusplus.com/reference/cctype/isspace/
24th Jan 2020, 11:44 PM
rodwynnejones
rodwynnejones - avatar