C trouble with a array,

ساخت وبلاگ

Vote count: 0

Hello i am fairly new to programming in C and basically the decrypt array only holds the first value entered into in below is my code also any tips to help me improve are appreciated;

int main(int argc, char *argv[]) {
char input[100] = "";
char target[0] = "";
char replace[0] = "";
char keycipher[100] = "";
int i, size;
static char decrypt[100] = ""; while(1){ printf("nEnter Target: "); fgets(target, 17, stdin); printf("Replace With: "); fgets(replace, 17, stdin); for(i = 0; i < size; i++) { if(input[i] == target[0]) { decrypt[i] = target[i];<-this is where it is supposed to be added input[i] = replace[0]; printf("n%s",input); printf("n%s",decrypt); } } if(target[0] == 'q' || replace[0] == 'q'){ break; }
}
printf("decryt @# %s", decrypt);
printf("nDecrypting .....n");
printf("Your orginal string was: ");
for(i = 0; i < 100; i++) { input[i] = decrypt[i]; printf("%s", input); }
printf("nSIMULATION OVER!n");
system("PAUSE");
retu 0;
}

the output i receive is as follows;

*--------------------------*
| Welcome to the Scrambler |
*--------------------------* Remember press q to quit
Please enter a string: hello stranger
you entered: hello stranger
Enter target: h
Replace with: w
wello stranger
decrypt array: h
Enter target: s
Replace with: p
wello ptranger
decrypt array: h <-------- why is this still just h?
Enter target: q
Replace with:
decrypt holds: h <----------
Decrypting .....
Your original string was: hello ptrangerhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
SIMULATION OVER!

also how can i check if the target is already in the array so they can`t add that character?

asked 2 mins ago

1 Answer

Vote count: 0

The problem is in

char target[0] = "";
char replace[0] = "";

zero-length arrays cannot be used meaningfully.

answered 12 secs ago

- - , .

back soft...
ما را در سایت back soft دنبال می کنید

برچسب : نویسنده : استخدام کار backsoft بازدید : 315 تاريخ : جمعه 30 بهمن 1394 ساعت: 22:38