Revision as of 19:58, 13 May 2024 by Admin (Created page with "<syntaxhighlight lang="C"> #define __STDC_WANT_LIB_EXT1__ 1 // Active C11 extended functions (this case is gets_s) #include<stdio.h> int slen(const char *); // I don't want to include whole string lib just for get size int main(void) { char s[500]; printf("%s","Enter a sentence: "); if(!gets_s(s,500)) { puts("Error!"); getchar(); return 0; } for(int i=0;i<slen(s);i++) if(s[i]!=32) putchar(s[i]); else putchar(10); putchar(10);...")
Exercise
ABy Admin
May 13'24
Answer
#define __STDC_WANT_LIB_EXT1__ 1 // Active C11 extended functions (this case is gets_s)
#include<stdio.h>
int slen(const char *); // I don't want to include whole string lib just for get size
int main(void) {
char s[500];
printf("%s","Enter a sentence: ");
if(!gets_s(s,500)) {
puts("Error!");
getchar();
return 0;
}
for(int i=0;i<slen(s);i++)
if(s[i]!=32)
putchar(s[i]);
else
putchar(10);
putchar(10);
getchar();
return 0;
}
int slen(const char *s) {
int i;
for(i=0;s[i]!=0;i++);
return i;
}