String Reverasal by Word in C:
#include<stdio.h>
int main() {
const char * s = " this is nitk surathkal ";
int len = strlen(s);
int i = len-1;
int j,k;
while (1)
{
//while (i>=0 && s[i] == ' ') i--;
if (i<0) break;
j=i;
while (i>=0 && s[i] != ' ') i--;
for ( k=i+1; k<=j; k++) printf("%c", s[k]);
printf(" ");
i--;
}
printf("\n");
}
Output: surathkal nitk is this
0 comments:
Post a Comment