0
What's wrong in this code
Spy code encryption
6 ответов
+ 1
#include <stdio.h>
#include<string.h>
int main() {
char ajith[50];
scanf("%s",ajith);
char delimis="%,+,*,=,1,2,3,4,5,6,7,8,9";
char *lone;
lone=strtok(ajith,delimis );
int i;
for(i=0;lone[i]!='\0';++i);
for(i=i-1;i>=0;i--)
printf("%c",lone[i]);
return 0;
}
0
line
char delimis="%,+,*,=,1,2,3,4,5,6,7,8,9";
is wrong:
1. delimis should be char pointer to the string of delimiters. In your code it is char.
2. delimiters in the string should be listed without comma.
replace it with
char *delimis="%+*=123456789";
strtok may return NULL if it doesn't find any delimiter and it will reach the end of the string.
You should check lone on the NULL;
if strtok has found delimiter in the string, it replaces it with a null character ('\0') and return poiner to it.
lines
for(i=0;lone[i]!='\0';++i);
for(i=i-1;i>=0;i--)
printf("%c",lone[i]);
return 0;
}
have a bug: at this moment lone can be either NULL or point to null character.
if it is NULL you will get access violation in the line
for(i=0;lone[i]!='\0';++i);
if it points to null character, line
for(i=0;lone[i]!='\0';++i);
has effect of i=0, as lone[0] is null character
lines
for(i=i-1;i>=0;i--)
printf("%c",lone[i]);
return 0;
}
can cause access violation if delimiter is the first character of the string
0
Can u rewrite my code in my way and fix bugs??
0
You didn't write your task explanation.
What should code output?
0
12D5÷/%L$#3RL66O5#W
DLROW
WORLD
0
Symbols should be removed and string be displayed
Then string should reversed