|
|
back to boardPlease HELP!!! Can anybody tell me what's wrong with this? When I test the program it works fine. I end the input using ctrl-D , Is that wrong? #include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> /*function to reverse a string*/ void strrev(char string[256]) { char reverse[256]; int i,j; i=strlen(string);
for (j=i-1;j>=0;j--) { reverse[i-1-j]=string[j]; } reverse[i]='\0'; strcpy(string,reverse); } int main(void) {
int k=0,i=0,j,different=0,start=0; int c; char stream[256]; char num[256]; char copy[256]; double number; while((c=getchar())!=EOF) { stream[i]=c; j=i; i++; }
for (k=j;k>=0;k--) { if(isdigit(stream[k])!=0) { if(isdigit(stream[k-1])!=0) { num[start]=stream[k]; start++; } else { num[start]=stream[k]; num[start+1]='\0'; // printf("%s\n",num); strrev(num); // printf("%s\n",num); strcpy(copy,num); number=strtod(copy,NULL); printf("%0.4f\n",sqrt(number)); start=0;
} } } return 0; } |
|
|