I am trying to insert into the output file letters:
The input file has numbers like that:
12
13
14
15
I want to create an output file with extension .new (which I did!)that assign a letter after each 2 number lines
like that:
12 a
13 b
14
15
16 a
17 b
...
Need help....Thanks
Here is my latest code
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
FILE *ofp;
FILE *ifp;
int main(int argc, char*argv[])
{
int k;
char fileline[50];
char *document;
char *p;
if (argc==2)
{
document=malloc(strlen(argv[1]) + sizeof(".new")+1);
strcpy (document, argv[1]);
}
else {perror("date2");exit(1);}
ifp=fopen(document,"r");
p = strrchr(document,'.');
if (p !=NULL ) *p = '\0';
strcat(document, ".new");
ofp=fopen(document,"w");
fgets(fileline,sizeof(fileline),ifp);
fputs(fileline,ofp);
fseek(ofp,4,SEEK_SET);
fprintf(ofp,"a");
rewind(ifp);
fseek(ifp,2,SEEK_SET);
fgets(fileline,sizeof(fileline),ifp);
fputs(fileline,ofp);
//fseek(ofp,4,SEEK_SET);
//fprintf(ofp,"b");
free(document);
fclose(ifp);
fclose(ofp);
return 0;
}