Mail Archives: djgpp/1997/09/06/14:36:36
On 6 Sep 97 07:17:18 GMT, Craig Rennie <carrac AT geocities DOT com> wrote:
>Does anybody know how I could go about changing a single character up 3
>characters which have been read from a file?
>eg. Reading "c" from a file and converting it to "f".
> or reading "%" and converting it to "(".
>
You can simply add the value '3' to the character. For example:
#include <stdio.h>
int main(void) {
FILE *fp;
char buffer[512];
int i;
if ((fp=fopen("myfile", "rt"))==NULL) {
printf("\nCan't open file!\n");
return 1;
}
fread(buffer, 512, 1, fp);
fclose(fp);
// convert characters here
for (i=0; i<512; i++) {
buffer[i]+=3;
}
// do whatever you want with the buffer here
return 0;
}
Nathan Thompson
---------------
Remove 'no.spam.' to reply.
- Raw text -