interesting problem in turbo C++, involving fopen
From: git_cs (git_cs_at_rediffmail.com)
Date: 04/30/04
- Next message: Neil Kurzman: "Re: Why is C good??? any experts?"
- Previous message: Kieran Simkin: "Re: Why is C good??? any experts?"
- Next in thread: Karthik: "Re: interesting problem in turbo C++, involving fopen"
- Reply: Karthik: "Re: interesting problem in turbo C++, involving fopen"
- Reply: Irrwahn Grausewitz: "Re: interesting problem in turbo C++, involving fopen"
- Reply: Martin Ambuhl: "Re: interesting problem in turbo C++, involving fopen"
- Reply: Martin Dickopp: "Re: interesting problem in turbo C++, involving fopen"
- Reply: CBFalconer: "Re: interesting problem in turbo C++, involving fopen"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 29 Apr 2004 23:28:41 -0700
Hey, guys and gals
Somedays ago, I had asked for the DES algorithm in C language.
Although I have written the algorthim in C myself, I am facing a
peculiar problem, which I hope some of u guys and gals solve.
I use Turbo C++ version 3.0 and WINXP as the operating system.
Pls observe the following program.
1 #include<stdio.h>
2 #include<conio.h>
3 main()
4 {
5 int i,j;
6 int ak;
7 char ch;
8 FILE *fp,*fs;
9 clrscr();
10 i=0;
11 fs=fopen("ak4.txt","w");
12 for(i=0;i<256;i++)
13 {
14 fputc(i,fs);
15 }
16 fclose(fs);
17 i=1;
18 fs=fopen("ak4.txt","r");
19 fp=fopen("ak5.txt","w");
20 i=0;
21 while(i!=EOF)
22 {
23 i=fgetc(fs);
24 printf("%d\n",i);
25 fprintf(fp,"%c",i);
26 fprintf(fp,"%d ",i);
24 }
25 }
I run the above program in Turbo C++, and winxp as operating system.
Then the file "ak4.txt", is created which will contain all the ascii
characters from 0-255.
But, from line 18, when I open the file "ak4.txt", and try to copy its
contents to another file
"ak5.txt", you will find a very interesting output.
First, that character whose ascii value is "13", has been ignored.
You can verify it on the screen output by pressing "Alt+F5", or in the
new file "ak5.txt".
Second, at character with ascii value "26", the while loop at line 21,
exits . In the file "ak5.txt", only 0-25 ascii characters(except 13)
are copied.
So, if insert the following line
if(i==26)
continue;
before line 14, then all the characters other than 26,13 will be
copied in file "ak5.txt".
Whew!!!, I hope I have been able to explain u.
My question: I am doing a project on DES algorithm. When I encrypt a
file, any ascii value from 0-255, might be the output. So, when I
want to decrypt it, those ascii values 13,26 do appear sometimes, and
cause the decryption to go haywire(13) or to exit the program
itself(26).
So, my friends is there a way out of this mess?
Have any of you faced the same problem. If yes? how did you solve it?
Will changing the compiler solve the problem?
Is there gcc compiler for windows too?
Please suggest some ideas. Because I intend to make a project which
runs on windows.
Note: The same DES program runs just fine on Linux.
- Next message: Neil Kurzman: "Re: Why is C good??? any experts?"
- Previous message: Kieran Simkin: "Re: Why is C good??? any experts?"
- Next in thread: Karthik: "Re: interesting problem in turbo C++, involving fopen"
- Reply: Karthik: "Re: interesting problem in turbo C++, involving fopen"
- Reply: Irrwahn Grausewitz: "Re: interesting problem in turbo C++, involving fopen"
- Reply: Martin Ambuhl: "Re: interesting problem in turbo C++, involving fopen"
- Reply: Martin Dickopp: "Re: interesting problem in turbo C++, involving fopen"
- Reply: CBFalconer: "Re: interesting problem in turbo C++, involving fopen"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]