-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathb.c
47 lines (43 loc) · 789 Bytes
/
b.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <string.h>
#define filename "a.txt"
FILE *fp;
void backpatch(int* arr, int len, int x)
{
fseek(fp,0,0);
int currLineNumber = 1;
for (int i = 0; i < len; ++i)
{
while(1)
{
if(currLineNumber == arr[i])
{
char temp[100];
sprintf(temp, "%d: goto %d", currLineNumber,x);
char cln[100];
sprintf(cln, "%d", currLineNumber);
int totallinelen = strlen(cln) + 12;
int spaceleft = totallinelen-strlen(temp);
while(spaceleft--)
sprintf(temp, "%s ", temp);
fputs(temp, fp);
break;
}
char c = getc(fp);
if(c=='\n')
{
currLineNumber++;
}
}
}
fseek(fp, 0, SEEK_END);
}
int main()
{
int arr[2] = {5,10};
int len = 2;
int x = 11;
fp=fopen(filename, "r+");
backpatch(arr, len, x);
return 0;
}