+ 1

The Spy Life

I am unable to encounter spaces between words, this is a challenge "The Spy Life". Anyone take a look plz and send me the correct code in C. My code is attached below. #include<stdio.h> #include<string.h> int main() { char ch[1000],ar[500]; int i,n,j=0; scanf("%[^\n]s\n",ch); n=strlen(ch); for(i=0;i<n;i++){ if(ch[i]>=97&&ch[i]<=122||ch[i]>=65&&ch[i]<=90){ ar[j]=ch[i]; j++; } } ar[j]='\0'; n=strlen(ar); for(i=n-1;i>=0;i--) { if((ar[i]>=65&&ch[i]<=90)&&(i==n)) printf("* "); printf("%c",ar[i]); } }

11th May 2020, 5:19 PM
Harshit Bhatt
Harshit Bhatt - avatar
4 Answers
+ 1
The ASCII code for space is 32. So add following to your if-condition: || ch[i] == 32
11th May 2020, 8:39 PM
Manu_1-9-8-5
Manu_1-9-8-5 - avatar
+ 1
Can't u just use isspace and isalpha?
5th Jul 2020, 6:02 PM
Roby
Roby - avatar
0
Thats ok but i don't get the idea about space, i.e after how many alphabets i will display space... I you understand my problem
12th May 2020, 4:12 AM
Harshit Bhatt
Harshit Bhatt - avatar
0
Here the example from Spy Life: Input: d89%l++5r19o7W *o=l645le9H Output: Hello World Basically you just reverse the complete input and print all alphabetic characters plus spaces. So you do not have to know after how many characters you have to print a space. You just print it when it ouccurs.
12th May 2020, 6:45 AM
Manu_1-9-8-5
Manu_1-9-8-5 - avatar