Have to reverse non-identifiers. identifiers: words that have characters from the set of "A"-"Z", "a"-"z", "0"-"9" or "_" (or so it is in my problem's case). it should also keep white spaces and new lines as in input.
my idea was to check string in advance and see if it contained anything beyond the identifier set, if yes then i would reverse the word.
#include <stdio.h>
#include <string.h>
int main()
{
int i, j, n;
char c;
char word[100000];
while(1)
{
word[0]='\0';
scanf("%s%c", word,c);
n=strlen(word); /* n is length of word */
if(n == 0)
{
break;
}
else if(c == '\n') printf("\n");
else if(c == ' ') printf(" ");
else
{
for(j = 0; j < n; j++) /* thought of checking every character in string */
{
if( (string[j] >= '!' && string[j] <= '/') ||
(string[j] >= ':' && string[j] <= '@') ||
(string[j] >= '[' && string[j] <= '`') ||
(string[j] >= '{' && string[j] <= '~') ) /* if any character of string is from following set, reverse word
loop for reversing word... prob need it outside of for(j = 0; j < n; j++) loop
for(i = n; i > 0; i--) printf("%c", word[i]); */
}
}
}
return 0;
}