name.txt
I
k
e
S
u
e
L
e
o
I hope I have not overstayed my welcome but I refuse to take the easy way out, I want to do all I can with C for as long as possible. How can I get the above text to print to screen like below and save it to a file with a difference name?
There may be better ways but I would like to know how this work because this is one of those time that I can’t even get lucky to get (%a,b, …) to do anything else except showing \n.
One other thing; how would I put each character into char buffers like in the code below? Even if its not needed here based on the code, I just want to how it is done.
new.txt
Ike
Sue
Leo
Code:#include <stdio.h>
#include <string.h>
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
int main() {
char buf1[1]; char buf2[1]; char buf3[1]; char buf4[1];
char cuf1[1]; char cuf2[1]; char cuf3[1]; char cuf4[1];
char duf1[1]; char duf2[1]; char duf3[1]; char duf4[1];
FILE *fptr, *fptw;
fptr=fopen("name.txt","r");
fptw=fopen("new.txt","w");
fseek(fptr, 0, SEEK_SET); int a = fgetc(fptr);
fseek(fptr, 2, SEEK_SET); int b = fgetc(fptr);
fseek(fptr, 4, SEEK_SET); int c = fgetc(fptr);
fseek(fptr, 5, SEEK_SET); int d = fgetc(fptr); // new line
fseek(fptr, 6, SEEK_SET); int e = fgetc(fptr);
fseek(fptr, 8, SEEK_SET); int f = fgetc(fptr);
fseek(fptr, 10, SEEK_SET); int g = fgetc(fptr);
fseek(fptr, 11, SEEK_SET); int h = fgetc(fptr); // new line
fseek(fptr, 12, SEEK_SET); int i = fgetc(fptr);
fseek(fptr, 14, SEEK_SET); int j = fgetc(fptr);
fseek(fptr, 16, SEEK_SET); int k = fgetc(fptr);
fseek(fptr, 17, SEEK_SET); int l = fgetc(fptr);
printf(": %c\n", a);
printf(": %c\n", b);
printf(": %c\n", c);
printf(":: %c\n", d);
printf(": %c\n", e);
printf(": %c\n", f);
printf(": %c\n", g);
printf(":: %c\n", h);
printf(": %c\n", i);
printf(": %c\n", j);
printf(": %c\n", k);
printf(":: %c\n", l);
// putchar(fgetc(fh));
// fgets(c);
// fprintf(fptr,"d", a);
// fprintf(buf1,"d", a);
fclose(fptr);
fclose(fptw);
return 0 ;
}