the program decodes the data(three lines) in a file and writes to an other file. but there are one line in the second file.so the program writes three lines as one line. how can I write as three lines to second file
the program decodes the data(three lines) in a file and writes to an other file. but there are one line in the second file.so the program writes three lines as one line. how can I write as three lines to second file
I think what you are asking is how to add carriage return and line feed to the end of each line. These characters are '\r' and '\n' respectively.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
post some code ..must be some minor error somewhere..
this is the code;
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
int main()
{
char coded[35];
int decode[35],i;
FILE * p;
p=fopen("message.dat","r"); // Opens the file with the coded text
for (int c=0;c<35;c++)
{
coded[c]=getc(p);
cout<<coded[c];
}printf("\n\n");
for(i = 0; i < 35; i++)
{
decode[i] = coded[i];
decode[i] -= 2;
}
p=fopen("unco.dat","w"); // Opens a new file with the decoded text
for (int cc=0;cc<35;cc++)
{
putc(char(decode[cc]),p);
cout << char(decode[cc]);
}
getche();
return 0;
}
Last edited by ercumania; 07-24-2006 at 05:47 AM.
Use code tags henceforth...
> how can I write as three lines to second file <
Where are u opening ur second file ?
And what kind of arrays are coded and decoded ?.. U dont even need these arrays if u r just trying to transfer the contents of one file to another
What exactly are u trying to do ?
better now,
Just remember that u need to set the parameter that catches the value that fgetc() returns as int... READ the FAQ for more details...
I think u can go with this for starters :
I am using C ..hope thats not a problem...
Didnt compile it . but, have a strong feeling it should workCode:int main() { int c; FILE *fp1,*fp2; fp1=fopen("file1.txt","r"); fp2= fopen("file2.txt" ,"w"); printf("contents of file1.txt \n"); while((c=getc(fp1))!=EOF) { fputc( c , fp2); printf("%c",c); } fclose(fp1); fclose(fp2); fp2=fopen("file2.txt","r"); printf(" contents of file2.txt \n"); while((c=getc(fp2))!=EOF) { printf("%c",c); } fclose(fp2); return 0; }
If u feel reading it char by char is too boring , u can think of fread and fwrite..