+ 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]); } }
4 Answers
+ 1
The ASCII code for space is 32. So add following to your if-condition:
|| ch[i] == 32
+ 1
Can't u just use isspace and isalpha?
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
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.