+ 2

HišŸ¤—! Can you find a bug in my code?

#include<stdio.h> #include<conio.h> #include<string.h> int count(); int main() { static char enter[20]; gets(enter); printf("sum=%d",count(enter)); getch(); } int count( sum) char *sum; { int count1=0,i=1; while((*(sum+i)!=" ")&&(*(sum+i)!='\n')&&(*(sum+i)!='\t')) { ++count1; i++; } return count1; }

23rd May 2021, 4:57 PM
Š”ŠøŠ»ŃˆŠ¾Š“ Усмонов
Š”ŠøŠ»ŃˆŠ¾Š“ Усмонов - avatar
2 Answers
+ 2
Ok, you made a few mistakes which i will point out and then please compare your code with the fixed version. First, #include<conio.h> and getch(); are uneeded. Second, dont use gets, use scanf Third, your while conditions were not set up quite right and you dont use ā€œ ā€ for space, use ā€˜\0’ Here is the fixed version of your code. https://code.sololearn.com/cf2fjR8I8i4x/?ref=app
23rd May 2021, 5:21 PM
Brain & Bones
Brain & Bones - avatar
+ 1
I want to count how many symbols are involved but it doesn’t do right🄺
23rd May 2021, 5:01 PM
Š”ŠøŠ»ŃˆŠ¾Š“ Усмонов
Š”ŠøŠ»ŃˆŠ¾Š“ Усмонов - avatar