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....
2 Antworten
+ 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
+ 2
Have a look at "isspace" from the "ctype.h" header file;
http://www.cplusplus.com/reference/cctype/isspace/